I need to troubleshoot PHP code to store the results of a poll, and to display the results. I have started the code but am really confused how to properly use the CREATE DATABASE, CREATE TABLE, INSERT and SELECT statements.
I need help with this, as well as how to display the results in a similar fashion to the below:
Your favorite flower is the Rose.
There are 500 total votes.
Rose received 10% of the total vote.
Daisy received 20% of the total vote.
Other received 70% of the total vote.
Please assist me with structuring the code, and/or direct me to a similar poll on the Internet, so that I may actually see code that works. Examples of how to use the above statements would be very helpful.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>My Favorites</title>
</head>
<body>
<FORM style="MARGIN-TOP: 0px; MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px"
name=Favorites action=Pollresults2.php method=post
target="">
<table width="33%" border="1" align="center" bordercolor="#333399">
<tr bordercolor="#333399">
<th scope="col">
<TABLE width=133 border=1 cellPadding=2 cellSpacing=0 bordercolor="#333399" bgColor=#ddeeff>
<TBODY>
<TR>
<TD bgColor=#5588cc>
<TABLE width="100%" border=1 cellPadding=0 cellSpacing=0 bordercolor="#FFFFFF">
<TBODY>
<TR>
<TD align=middle>
<div align="center"><FONT face=verdana,arial,sans-serif color=#ffffff size=2><B>My Favorites</B></FONT></div>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD>
<div align="center"><FONT face=verdana,arial,sans-serif color=#000000 size=1>Which is your favorite Flower?<BR>
</FONT>
<TABLE border=1 bordercolor="#333399">
<TBODY>
<TR>
<TD vAlign=top>
<INPUT type=radio value=Daisy name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Daisy</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=Rose name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Rose</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=Tulip name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Tulip</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<input type=radio value=Lily name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Lily</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=Orchid name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Orchid</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=Lilac name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Lilac</FONT></TD>
</TR>
<TR>
<TD vAlign=top>
<INPUT type=radio value=Other name=Flower>
</TD>
<TD vAlign=center><FONT face=verdana,arial,sans-serif color=#000000
size=1>Other</FONT></TD>
</TR>
</TBODY>
</TABLE>
<BR>
</div>
</TD>
</TR>
</TBODY>
</TABLE>
</th>
<br>
<br>
<table width="100%" cellspacing="5" cellpadding="5">
<tr>
<th scope="col">
<INPUT type=submit value="Submit Vote" name=poll_submit>
</th>
</tr>
</table>
<br>
</FORM>
</body>
</html>
</head>
<body>
<form action="Poll2.html" method="get">
<style type="text/css">
<!--
.style1 {
color: #333399;
font: bold 24px Arial;
text-align: center;
-->
</style>
<p class="style1">Le Fleur!</p>
<strong><p class="style5"> Thank you for your vote. Below are the results.
<br>
If you did not vote, please hit the back button and do so. </p> </strong>
<br>
<?php
/* insert into table */
$selectedFlower = Request.Form("Poll2.html");
$inserQuery="insert into Poll2.html (response) values (" + selectedFlower + ")";
mysql_query($inserQuery);
?>
<?php
if ( $Flower == "" ) {
$error=true;
echo "Please vote.";
} else {
echo "Your favorite flower is the: $Flower."; }
?>
<br><br>
<?php
$query="select (sum( response) /count(*)) as '% Votes'; }
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
echo "The Poll Results Are:" ; }
while ($i < $num) {
?>
<?php
$percentageVotes = mysql_result($result,$i,"% Votes");
$flowerName = mysql_result($result,$i,"response"); }
<?php
if( $flowerName = 'F1'){
$flowerName = 'Rose';
}else if($flowerName = 'F2'){
$flowerName = 'Daisy';
}else if($flowerName = 'F3'){
$flowerName = 'Tulip';
}else if($flowerName = 'F4'){
$flowerName = 'Lily';
}else if($flowerName = 'F5'){
$flowerName = 'Orchid';
}else if($flowerName = 'F6'){
$flowerName = 'Lilac';
}else if($flowerName = 'F7'){
$flowerName = 'Other';
?>
<?php
select (count( response) /count(*)) as '% Votes' </td><td>$flowerName </td></tr>"; }
$i++;
}
?>
<br><br>
<input type="Submit" value="BACK" name="Submit">
<br>
<p class="style5"> <strong>Thanks again for your time.</strong> </p>
</form>
</body>
</html>