I am trying to create a very basic star rating system for a simple website. I found this tutorial : Creating 5 Star Rating System With PHP , MySQL ,Jquery And Ajax
however, when I run the same code, I keep getting the following error an no votes get inserted into the database:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-databaseName.ratings WHERE id='1'' at line 1
This is the code for the page to insert the ratings:
<?php
include("settings.php");
connect();
$ids=array(1,2,3);
?>
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="rating.css" />
<script type="text/javascript" src="rating.js"></script>
</head>
<body>
<?php
for($i=0;$i<count($ids);$i++)
{
$rating_tableName = 'ratings';
$id=$ids[$i];
$q="SELECT * FROM ratings WHERE id='$id'";
$r=mysql_query($q);
echo $q;
if(!$r) echo mysql_error();
$rat = 0;
$v = 1; // In case there are no records.
while($row=mysql_fetch_array($r))
{
$v = $row['total_votes'];
$tv = $row['total_value'];
$rat = $tv/$v;
}
$j=$i+1;
$id=$ids[$i];
echo'<div class="product">
Rate Item '.$j.'
<div id="rating_'.$id.'" class="ratings">';
for($k=1;$k<6;$k++){
if($rat+0.5>$k)$class="star_".$k." ratings_stars ratings_vote";
else $class="star_".$k." ratings_stars ratings_blank";
echo '<div class="'.$class.'"></div>';
}
echo' <div class="total_votes"><p class="voted"> Rating: <strong>'.@number_format($rat).'</strong>/5 ('.$v. ' vote(s) cast)
</div>
</div></div>';}
?>
</body></html>
I did try everything that i thought might solve the issue but nothing worked;
I tried to add back slashes and single quotes for the $id
and it still throws that error.
I also echoed $q as mentioned on that page and i get the exact same thing that was mentioned on that page!
the only thing that I am a bit suspicious about is the fact that it is not showing the full database name in the error message.
the database name is like this: CL12-databaseName
but in the error above its showing the database as -databaseName
and i'm not sure if it suppose to do that or is that something that is causing the error ?
any help would be appreciated.
Thanks