Jump to content

Cookie Help


twan

Recommended Posts

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 data
while($ratings = mysql_fetch_array( $query ))
{

//This outputs the sites name
echo "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 item
echo "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 link
if ( $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 rating
mysql_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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.