I'm trying to set up a simple little rating system for videos on a website. If you push + it adds 1 and if you push - it subtracts 1. I've got it working just fine. However, the way i'm checking to see if you've rated it already is by searching for it inside a column called 'rated' that holds the usernames of each user that has rated it. I can see it becoming an issue if someone has a similar username as someone else. Is there a better way to go about this?
<?php
include("db_config.php");
include("approve.php");
$id=$_GET['id'];
$path=$_GET['path'];
$sql3="SELECT COUNT(*) as num FROM videos WHERE rated LIKE '%$_SESSION[username]%' and path1 = '$path'";
$result3=mysql_fetch_array(mysql_query($sql3));
$result3=$result3[num];
if($result3==0){
$sql1="SELECT * FROM videos WHERE path1 = '$path'";
$result1=mysql_query($sql1);
while($rows=mysql_fetch_array($result1)){
$rating=$rows['rating'];
$rated=$rows['rated'];
$rated=$rated.'.'.$_SESSION['username'];
}
if($id=="minus") {$rating = $rating - 1;}
if($id=="plus") {$rating = $rating + 1;}
$sql2 = "UPDATE videos SET rating='$rating', rated='$rated'
WHERE path1 = '$path'";
$result2 = mysql_query($sql2);
if($result2) {
header("location:view_video.php?path=$path");
}
}
else {
header("location:view_video.php?path=$path&id=1");
}
?>