//fill in the color variable with a hex code for a color.
$color = "#2956A9";
//For the lines below, use the following stuff...
//if you want to record peoples usernames when they vote..change $remote_addr to a variable with the user's
//username. $remote_addr is the users Ip address.
$ident = "$logged[username]";
//change the following line to where u want the user to be redirected
//after they vote
$ref = $_SERVER['HTTP_REFERER'];
if (!$ref)
{
$ref = "?view=home";
}
$redir = "$ref";
include ("config.php"); // the page that connects to the database
$checkvoted = mysql_query("SELECT * from poll_votes where ident = '$ident' AND poll_id = '$getq[id]'");
$voted = mysql_num_rows($checkvoted);
if ($voted == 0 && !$_POST[pollsubmit])
{
$getchoice1 = mysql_query("SELECT * from poll_choices WHERE pollid = '$getq[id]' order by 'id' asc");
echo ("
");
}
if ($_POST[pollsubmit] && $voted == 0)
{
$pchoiceq= mysql_query("SELECT * from poll_choices WHERE pollid = '$getq[id]' order by 'id' asc");
while ($pchoices = mysql_fetch_array($pchoiceq)){
$choiceid = $pchoices[id];
if ($_POST[choice] == $choiceid && $voted == 0)
{
$update_votes = mysql_query("Update poll_choices set votes = votes + 1 where id = '$choiceid'");
$fvote = mysql_query("INSERT INTO `poll_votes` ( `poll_id`, `ident`, `choice`, `date` )VALUES ('$getq[id]', '$ident', '$choiceid', NOW())");
echo ("
Thank You for voting!");
}
}
}
if ($voted == 1)
{
$totalvotes = 0;
$getnumvotes = mysql_query("SELECT * from poll_choices where pollid = '$getq[id]' order by 'id' asc");
while($votes = mysql_fetch_array($getnumvotes))
{
$totalvotes = $totalvotes + $votes[votes];
}
$getpoll1 = mysql_query("SELECT * from poll_choices where pollid = '$getq[id]' order by 'id' asc");
while ($getpoll = mysql_fetch_array($getpoll1))
{
$numvotes = $getpoll[votes] / $totalvotes;
$numvotes2 = $numvotes * 100;
echo ("$getpoll[text]");
$round = ceil($numvotes2);
echo (" ($getpoll[votes] votes)
");
}
}
echo "
Total Votes: $totalvotes
";
?>