Below is code that I’m trying to use to set up a web poll. for some reason I cannot get it to record any results. I get no error message and nothing is sent to the data base
I posted the table structure below
[code=php]
<?PHP
include ‘../db.php’;
if($_POST[“Vote”] == “Option1”) {
$Votes1 = $PollData[“Option1”] + 1;
$TotalVotes = $PollData[“Votes”]+ 1;
$sql = “UPDATE `poll_data` SET `Option1`=’$Votes1′, `Votes`=’$TotalVotes’ WHERE `ID` = ‘”. $PollData[‘ID’] . “‘ LIMIT 1”;
if(!($result = mysql_query($sql))) die(mysql_error());
/*echo “Vote successful! <a href=’poll.php’>Back</a> to the poll.”;*/
}
else if ($_POST[“Vote”] == “Option2”){
$Votes2 = $PollData[“Option2”] + 1;
$TotalVotes = $PollData[“Votes”]+ 1;
$sql = “UPDATE `poll_data` SET `Option2`=’$Votes2′, `Votes`=’$TotalVotes’ WHERE `ID` = ‘”. $PollData[‘ID’] . “‘ LIMIT 1”;
if(!($result = mysql_query($sql))) die(mysql_error());
/*echo “Vote successful! <a href=’poll.php’>Back</a> to the poll.”;*/
}
else {
$Votes3 = $PollData[“Option3”] + 1;
$TotalVotes = $PollData[“Votes”] + 1;
$sql = $sql = “UPDATE `poll_data` SET `Option3`=’$Votes3′, `Votes`= ‘$TotalVotes’ WHERE `ID` = ‘”. $PollData[‘ID’] . “‘ LIMIT 1”;
if(!($result = mysql_query($sql))) die(mysql_error());
/*echo “Vote successful! <a href=”poll.php”>Back</a> to the poll.”;*/
}
?>
<form method=”POST” action=”<? $PHP_SELF ?>”>
<table width=”500″ border=”1″ cellspacing=”0″ cellpadding=”8″>
<tr>
<td colspan=”3″><b><?=$PollData[‘Title’]?> – <?=$PollData[‘Question’]?></b></td>
</tr>
<tr>
<td width=”35%”>
<input type=”radio” name=”Vote” value=”Option1″>
Yes</td>
<td width=60%>
<img src=”http://localhost/familyclick/images/bar.gif” width=”<?=$VotePercent1?>” height=”20″>
</td>
<td><?=$VoteData[“Option1″]?> Votes</td>
</tr>
<tr>
<td width=”35%”>
<input type=”radio” name=”Vote” value=”Option2″>
No </td>
<td width=60%>
<img src=”http://localhost/familyclick/images/bar.gif” width=”<?=$VotePercent2?>” height=”20″>
</td>
<td><?=$VoteData[“Option2″]?> Votes</td>
</tr>
<tr>
<td width=”35%”>
<input type=”radio” name=”Vote” value=”Option3″ >
Not Sure</td>
<td width=”60%”>
<img src=”http://localhost/familyclick/images/bar.gif” width=”<?=$VotePercent3?>” height=”20″>
</td>
<td><?=$VoteData[“Option3″]?> Votes</td>
</tr>
<tr>
<td colspan=”3″>
<center>
<input type=”submit” name=”Submit” value=”Vote”>
</center>
</td>
</tr>
</table>
</form>
</body>
</html>
[code=php]
<?PHP
include ‘db.php’;
mysql_query(“CREATE TABLE poll_data (
ID tinyint(4) NOT NULL auto_increment,
Option1 tinyint(4) NOT NULL default ‘0’,
Option2 tinyint(4) NOT NULL default ‘0’,
Option3 tinyint(4) NOT NULL default ‘0’,
Votes tinyint(4) NOT NULL default ‘0’,
Title varchar(25) NOT NULL default ”,
Question varchar(50) NOT NULL default ”,
PRIMARY KEY (ID))”)or die(“Create table Error: “.mysql_error());
?>