<?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();
}
?>
基本上我是怎么写GETs
的
?u=用户名&v=video0009&like=4
我希望 like=4 然后更新INT
视频和用户名匹配的位置。虽然它一直保持在0。
还要保留这些,INT
以便以后我可以将它们与mysqli_fetch_assoc
? 只是好奇