latheesan
07-26-2006, 05:33 PM
Hello,
This is a small snippet of my poll voting script:
if($_GET["act"] == "vote")
{
$poll_id = $_POST["poll_id"] ? $_POST["poll_id"] : '';
$poll_option = $_POST["option"] ? $_POST["option"] : '';
if($_COOKIE["poll_voted"] == "yes" && $_COOKIE["poll_voted_id"] == $poll_id)
{
$error .= '<font color="#cc0000">Sorry, you can vote only once per hour, per poll!</font><br>';
}
else
{
include("inc/mysql.php");
$query = "SELECT * FROM poll_questions WHERE id = '". mysql_real_escape_string($poll_id) ."' LIMIT 1";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if($num >= 1)
{
setcookie("poll_voted", "yes", time()+3600);
setcookie("poll_voted_id", $poll_id, time()+3600);
$query2 = "UPDATE `poll_options` SET `votes` = `votes` + 1 WHERE `option` = '". $poll_option ."' AND `poll_id` = ". $poll_id ."";
mysql_query($query2);
mysql_close();
$success .= '<font color="#009D00">Thanks, you have successfully voted for this poll and your vote has been accepted</font>';
}
else
{
mysql_close();
$error .= '<font color="#cc0000">Sorry, you have specified an invalid Poll ID</font><br>';
}
}
}
Cookie isnt getting set, thus, the user can vote unlimited times... can u help plz, duno where i went wrong...
This is a small snippet of my poll voting script:
if($_GET["act"] == "vote")
{
$poll_id = $_POST["poll_id"] ? $_POST["poll_id"] : '';
$poll_option = $_POST["option"] ? $_POST["option"] : '';
if($_COOKIE["poll_voted"] == "yes" && $_COOKIE["poll_voted_id"] == $poll_id)
{
$error .= '<font color="#cc0000">Sorry, you can vote only once per hour, per poll!</font><br>';
}
else
{
include("inc/mysql.php");
$query = "SELECT * FROM poll_questions WHERE id = '". mysql_real_escape_string($poll_id) ."' LIMIT 1";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if($num >= 1)
{
setcookie("poll_voted", "yes", time()+3600);
setcookie("poll_voted_id", $poll_id, time()+3600);
$query2 = "UPDATE `poll_options` SET `votes` = `votes` + 1 WHERE `option` = '". $poll_option ."' AND `poll_id` = ". $poll_id ."";
mysql_query($query2);
mysql_close();
$success .= '<font color="#009D00">Thanks, you have successfully voted for this poll and your vote has been accepted</font>';
}
else
{
mysql_close();
$error .= '<font color="#cc0000">Sorry, you have specified an invalid Poll ID</font><br>';
}
}
}
Cookie isnt getting set, thus, the user can vote unlimited times... can u help plz, duno where i went wrong...
