/    Sign up×
Community /Pin to ProfileBookmark

Web poll not working

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]

[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());

?>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...