twan Posted September 9, 2006 Share Posted September 9, 2006 I am having a problem with storing a cookie from when someone votes so that they cannot vote again. As the code is now, a person can vote for a game as many times as they please. Here is my code I hope someone can help me. Thank you.[code]//Puts SQL Data into an array$query = mysql_query("SELECT * FROM games WHERE gamename LIKE '%$search%' LIMIT 1");//Now we loop through all the datawhile($ratings = mysql_fetch_array( $query )){//This outputs the sites nameecho "Name: " .$ratings['gamename']."<br>";//This calculates the sites ranking and then outputs it - rounded to 1 decimal$current = $ratings[userrating] / $ratings[totalrating];echo "Current Rating: " .round($current, 2) . "<br>";//This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular itemecho "Rank Me: ";echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&id='.$ratings[number].'><img src='control1.jpg' border='0' name='control' onMouseOver='over(0)' onMouseOut='out(0)' ></a>";echo ("<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=2&id='.$ratings[number].'><img src='controller1.jpg' border='0' name='controller' onMouseOver='over(0), over(1)' onMouseOut='out(0), out(1)'></a>");echo ("<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=3&id='.$ratings[number].'><img src='rate1.jpg' border='0' name='rate' onMouseOver='over(0), over(1), over(2)' onMouseOut='out(0), out(1), out(2)'></a>");echo ("<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&id='.$ratings[number].'><img src='rating1.jpg' border='0' name='rating' onMouseOver='over(0), over(1), over(2), over(3)' onMouseOut='out(0), out(1), out(2), out(3)'></a>");echo ("<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=5&id='.$ratings[number].'><img src='three1.jpg' border='0' name='three' onMouseOver='over(0), over(1), over(2), over(3), over(4)' onMouseOut='out(0), out(1), out(2), out(3), out(4)'></a>");echo "<p>";}print ("$id");//We only run this code if the user has just clicked a voting linkif ( $mode=="vote"){$cookie = "Mysite$id";echo $cookie; if(isset($_COOKIE[$cookie])){Echo "Sorry You have already ranked that game <p>";} 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 ratingmysql_query("UPDATE games SET userrating = userrating + $voted, `totalrating` = totalrating + 1 WHERE gamename LIKE '%$search%' LIMIT 1 ");echo "Your vote has been cast <p>";echo $_COOKIE[$cookie];}}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.