//This runs if it is in voted mode
if ( $mode=="voted")
{
//makes sure they haven't already voted
if(isset($_COOKIE[$cookie]))
{
Echo "Sorry You have already voted this month<br>";
}
//sets a cookie
else
{
$month = 2592000 + time();
setcookie(Voted, Voted, $month);
// adds their vote to the database
switch ($vote)
{
case 1:
mysql_query ("UPDATE votes SET first = first+1");
break;
case 2:
mysql_query ("UPDATE votes SET sec = sec+1");
break;
case 3:
mysql_query ("UPDATE votes SET third = third+1");
}
//displays the poll results
pie ();
}
}
The next section of code runs if our voting form has been submitted. It first checks the user to see if they already have a voted cookie. If they do, it does not let them vote again and gives them an error message. However, if they do not, it
sets the cookie in their browser and then adds their vote to our database. Finally, it displays the results of the poll by running our
pie function.