Can someone please help me write code for a poll. I have written most of the code but I think I have gone wrong somewhere and need someone to check it for me.
I also don't understand how to link it my mysql database?
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
$choices = array('Economics', 'Mathematics', 'Medicine', 'Veterinary Science', 'Law'); echo ",table><tr><td><b>Results:</b><table><tr><td>".($mod_c_one-1)."</td><td>".$choices[0]."</td></tr><tr><td>".($mod_c_two-1)."</td><td>".$choices[1]."</td></tr><tr><td>".($mod_c_three-1)."</td><td>".$choices[2]."</td></tr><tr><td>".($mod_c_four-1)."</td><td>".$choices[3]."</td></tr></tables></td>"; displayPoll('Which University course will earn you the most money?', $choices); if(isset($_POST['submit'})){ if(isset($_POST['Poll'})) $selection = $_POST['Poll']; else $selection = "";
if(strlen($selection) > 0){ switch((int)$selection){ case 0: $select_stmt = "UPDATE poll SET c_one = $mod_c_one WHERE id = 1"; break; case 1: $select_stmt = "UPDATE poll SET c_two = $mod_c_two WHERE id = 1"; break; case 2: $select_stmt = "UPDATE poll SET c_three = $mod_c_three WHERE id = 1"; break; case 3: $select_stmt = "UPDATE poll SET c_four = $mod_c_four WHERE id = 1"; break; }
$process = mysql_query($selection_stmt) or die(mysql_error()); if($process) echo "Your vote has been casted => "; else echo "Error";
echo $choices[$selection];
}else echo "You made no choices!";
?>
Last edited by codeseeker; 01-07-2012 at 12:18 AM..
First of all, I assume you're storing each item to poll in the database,
and you also need to store the accumulative value and how many there are.
It appears like you might be doing that ... am I correct?
That's all you need to know ... $avg = total / how many
Percent? Percent of what?
Here's another error I found ... put single quotes around variables in your queries ...
$select_stmt = "UPDATE poll SET c_one = '$mod_c_one' WHERE id = 1";