Hi there, Im fairly new to PHP, and jut wrote my first real script. Its a voting script using cookies and it works very well, except to a very few amount of people. When a user votes, the script processes their vote, increase the variable to include their vote, and then set the cookie, then resets the script. The script reads the cookie, and if its set, it displays the amount of votes, and doesnt let you vote again. There are a few people however, when they submit a vote, it writes the new vote, but doesnt display the amount of votes, it goes back to the main vote screen. Attached is the script itself to help you understand.
<?
##############
phpVote
(C) MechWars
##############
ob_start("ob_gzhandler");
require "votedata.php";
require "votes.php";
if ($voted == "TRUE") {
?>
<head>
<title>phpVote</title>
<link rel='stylesheet' href='style.css' type='text/css'>
</head>
<BODY bgcolor="#000000" rightMargin="0" leftMargin="0" bottomMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<table width="100%" cellpadding="0" cellspacing="1" border="0" bgcolor="#666666">
<tr>
<td bgcolor="#000000"><center><?=$q?></center></td>
</tr>
<tr>
<td bgcolor="#000000"><?=$a1?>: <?=$a1votes?></td></tr>
<tr>
<td bgcolor="#000000"><?=$a2?>: <?=$a2votes?></td></tr>
<tr>
<td bgcolor="#000000">You have already voted in this poll!</td></tr>
</table>
<?
} else {
?>
<head>
<title>phpVote</title>
<link rel='stylesheet' href='style.css' type='text/css'>
</head>
<BODY bgcolor="#000000" rightMargin="0" leftMargin="0" bottomMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<table width="100%" cellpadding="0" cellspacing="1" border="0" bgcolor="#666666">
<form action="vote.php?act=vote" method="post">
<tr>
<td bgcolor="#000000"><center><?=$q?></center></td>
</tr>
<tr>
<td bgcolor="#000000"><input type="radio" name="answer" value="a1" class="radio"> <?=$a1?></td></tr>
<tr>
<td bgcolor="#000000"><input type="radio" name="answer" value="a2" class="radio"> <?=$a2?></td></tr>
<tr>
<td bgcolor="#000000"><center><input type="image" name="submit" border="0" src="http://planetannihilation.com/mechwars/images/votebutton.jpg"></center></td></tr>
</form>
</table>
<?
}
if ($act == "vote") {
if (empty($answer)) {
header("Location: vote.php");
}
setcookie("voted", "TRUE", time()+3600);
require "votes.php";
if ($answer == a1) {
$a1votes++;
} elseif ($answer == a2) {
$a2votes++;
}
$fp = fopen("votes.php", "w");
$data = "<?php\n\n";
$data .= "\$a1votes = \"$a1votes\";\n";
$data .= "\$a2votes = \"$a2votes\";\n";
$data .= "?>";
fwrite($fp, $data);
fclose($fp);
header("Location: vote.php");
}
?>