Rating System Help

Could someone please review the information below and tell me where I’m making a mistake. It pulls the information from the database correctly. However, when a vote link is pushed it does not post the results to the database currently. The page refreshes it pops up and says the vote has been sent however it does not show the changes in the MySQL database nor does it record an additional vote in the system.

Any help would be appreciated!

Thanks,
Jordan

<?php // Connects to your Database mysql_connect("localhost", "allstar_main", "edward2112") or die(mysql_error()); mysql_select_db("allstar_main") or die(mysql_error()); //Puts SQL Data into an array $data = mysql_query("SELECT * FROM rec_bourbon") or die(mysql_error()); //We only run this code if the user has just clicked a voting link if ( $mode=="vote") {

//If the user has already voted on the particular thing, we do not allow them to vote again $cookie = “Mysite$id”;
if(isset($_COOKIE[$cookie]))
{
Echo "Sorry You have already ranked that site

";
}

//Otherwise, we set a cooking telling us they have now voted
else
{
$month = 2592000 + time();
setcookie(Mysite.$id, Voted, $month);

	 //Then we update the voting information by adding 1 to the total votes and adding their vote (1,2,3,etc) to the total rating 

mysql_query (“UPDATE vote SET total = total+$voted, votes = votes+1 WHERE id = $id”);
Echo "Your vote has been cast

“;
}
}
//Now we loop through all the data
while($ratings = mysql_fetch_array( $data ))
{
//This outputs the sites name
Echo “Name: " .$ratings[‘title’].”
”;

//This calculates the sites ranking and then outputs it - rounded to 1 decimal
$current = $ratings[total] / $ratings[votes];
Echo "Current Rating: " . round($current, 1) . “
”;

//This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular item
Echo “Rank Me: “;
Echo “<a href=”.$_SERVER[‘PHP_SELF’].”?mode=vote&voted=1&id=”.$ratings[id].">Vote 1 | “;
Echo “<a href=”.$_SERVER[‘PHP_SELF’].”?mode=vote&voted=2&id=".$ratings[id].">Vote 2 | “;
Echo “<a href=”.$_SERVER[‘PHP_SELF’].”?mode=vote&voted=3&id=".$ratings[id].">Vote 3 | “;
Echo “<a href=”.$_SERVER[‘PHP_SELF’].”?mode=vote&voted=4&id=".$ratings[id].">Vote 4 | “;
Echo “<a href=”.$_SERVER[‘PHP_SELF’].”?mode=vote&voted=5&id=".$ratings[id].">Vote 5

";
}

?>

You can’t use $mode, you must use $_GET[‘mode’] or $_REQUEST[‘mode’], you only can use this code if apache (or web server) is configured with register_globals, and this is NOT RECOMMENDED by security.
Change
if ( $mode==“vote”)
to
if ( $_GET[‘mode’]==“vote”)

And Change :
“WHERE id = ‘$id’”;
to
“WHERE id = '”.$_REQUEST[‘id’]."’";

Sponsor our Newsletter | Privacy Policy | Terms of Service