I thought I could figure this out but I can't. I have a form that captures data from a couple of questions(it's a poll):
<form style="width: 500px; padding: 5px;" action="" method="post"><fieldset>
<legend>2009 Massachusetts Government Survey</legend>
Are you satisfied with the state's governor's performance?<br />
<input name="current" type="radio" value="yes" />Yes<br />
<input name="current" type="radio" value="no" />No<br />
<br />
Will you vote for your current party affiliation in the next election?<br />
<input name="affiliation" type="radio" value="yes" />Yes<br />
<input name="affiliation" type="radio" value="no" />No<br /><br />
How would you rate the performance of the state legislature during the govenor's term thus far?<br />
<select name="rating">
<option value="No opinion">No opinion</option>
<option value="Poor">1:Poor</option>
<option value="Fair">2:Fair</option>
<option value="Adequate">3:Adequate</option>
<option value="Good">4:Good</option>
<option value="Excellent">5:Excellent</option>
</select><br />
<br />
<input name="submit" type="submit" value="Send " /> <input name="Clear" type="reset" />
</form>
and here's the PHP to insert into the MySQL database:
<?
$current = $_POST['current'];
$affiliation = $_POST['affiliation'];
$rating = $_POST['rating'];
$hostname = "localhost";
$db_user = ""; // database password
$db_password = ""; // database password
$database = ""; //database name
# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
// db connection
if (isset($_REQUEST['submit'])) {
# insert data
$sql = "INSERT INTO results(id, question1, question2, question3) values ('', '$current', '$affiliation', '$rating')";
if($result = mysql_query($sql ,$db)) {
echo 'Your poll was entered';
} else {
echo "ERROR: ".mysql_error();
}
} else {
?>
What I'm trying to do is get the results from each question. For example, I would like to show "The current results for Question 1 are 23 Yes, 54 No" where the quantities of yes and no are pulled from the database. I just can't seem to figure the logic. Any help would be appreciated