Cookie Trouble
Posted: Thu Feb 09, 2012 10:28 pm
I have this poll code
<?php echo "Which is your favourite film?<br><form action='' method='post'>\n";
$query = mysql_query("SELECT movie, movieid, votes FROM moviepoll ORDER BY movieid");
while ($result = mysql_fetch_assoc($query))
{
echo "<input type='radio' name='box' id='box", $result["movieid"], "' value='", $result["movie"], "'>";
echo "<label for='box", $result["movieid"], "'>", $result["movie"], "</label> (currently has ", $result["votes"], " votes) <br>\n";
}
echo "<input type='submit'>\n</form>";
$movie = $_POST["box"];
if(isset($movie))
{
$expire = time() +30;
if(isset($_COOKIE["voted"]))
{
echo "Sorry, you've voted already";
}
else
{
$query = mysql_query("SELECT movie, movieid FROM moviepoll WHERE movie='$movie'");
$result = mysql_fetch_assoc($query);
$id = $result["movieid"];
$name = $result["movie"];
$sql = "INSERT INTO moviepoll (movieid, movie) VALUES ($id, '$name') ON DUPLICATE KEY UPDATE votes = votes + 1";
mysql_query($sql);
if(time() > $expire)
{
setcookie("voted", $name, time()-30);
}
setcookie("voted", $name, $expire);
}
}
?> and am trying to use cookies to limit the user voting again for a while, but I can't seem to get the cookies worked out, can you help?