<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers : Content-Type");
include_once("db_connect.php");
if(isset($_GET["u"])){
$username = $_GET['u'];
} else {
echo "No UserName";
exit();
}
if(isset($_GET["v"])){
$video= $_GET['v'];
} else {
echo "No Video ID";
exit();
}
if(isset($_GET["like"])){
$like = $_GET["like"];
} else {
echo "No Like Parameter added.";
}
$sql = "SELECT * FROM rating WHERE video='$video' LIMIT 1";
$video_query = mysqli_query($db_connection, $sql);
$numrows = mysqli_num_rows($video_query);
if($numrows < 1){
$sql = "INSERT INTO rating (video,username)
VALUES ('$video','$username')";
$video_query = mysqli_query($db_connection, $sql);
}
if(isset($_GET['like'])){
$counter = (int)$_GET["like"];
if($counter > 5 || $counter < 1){
echo "Rating Seems To Be Off?";
exit();
}
$sql = "UPDATE rating SET like='$counter' WHERE video='$video' AND username='$username'";
$video_query = mysqli_query($db_connection, $sql);
echo "Voted";
}else {
echo "No Parameter to Vote was applied";
exit();
}
?>
Basically how I am writing the GETs
are
?u=USERNAME&v=video0009&like=4
I want the like=4 to then update the INT
from where the Video and Username match. Though it keeps staying at 0.
Also Keeping these as INT
will that make it so that later I can count these together with mysqli_fetch_assoc
? just curious