Problem with simple quiz
Posted: Sun Jul 17, 2005 6:23 pm
Sorry folks, just doing a beginners PHP book to learn, but cannot figure out what I'm doing wrong. I'm suppose to make a quiz with 3 questions one with INPUT TYPE="text", INPUT TYPE="radio", OPTION VALUE (drop down menu). For each question I need to assign 10 points if correct. Here's what I have so far. Here's the HTML page for fname, lname, and questions:
Here is my PHP calc.php page:
I can only seem to get the $result1 to work, but $result2 and $result3 will not add up at all. Not sure if i'm doing it correctly, thanks =\
JCART | Please use
Code: Select all
<HTML>
<HEAD>
<TITLE>Quiz Project</TITLE>
</HEAD>
<BODY>
<!-- This will show what method to use and what file to use -->
<FORM METHOD="e;post"e; ACTION="e;Calc.php"e;>
<!-- First and last name entry boxes -->
Enter your first name:<br>
<INPUT TYPE="e;text"e; NAME="e;fname"e; SIZE=20></p>
Enter your last name:<br>
<INPUT TYPE="e;text"e; NAME="e;lname"e; SIZE=20><br></p>
<!-- Question 1 -->
Question 1:<br>
What is 3 + 5?:<br>
<INPUT TYPE="e;text"e; NAME="e;question1"e; SIZE=20><br></p>
<!-- Question 2 using input type radio dials -->
Question 2<br>
What is 3 * 5?<br>
<INPUT TYPE="e;radio"e; name="e;question2"e; value="e;10"e;> 10<br>
<INPUT TYPE="e;radio"e; name="e;question2"e; value="e;15"e;> 15<br>
<INPUT TYPE="e;radio"e; name="e;question2"e; value="e;20"e;> 20<br></p>
<!-- Question 3 using input type drop down menu "e;option"e; -->
Question 3<br>
What is 3 - 5?<br>
<P><SELECT NAME="e;question3"e;>
<OPTION VALUE="e;a"e;>-2</OPTION>
<OPTION VALUE="e;b"e;>-1</OPTION>
<OPTION VALUE="e;c"e;>0</OPTION>
</SELECT></P>
<!-- The input button for final calculation -->
<INPUT TYPE="e;submit"e; NAME="e;submit"e; Value="e;Grade me!"e;>
</FORM></BODY></HTML>Here is my PHP calc.php page:
Code: Select all
<?
// Checks for missing values in these VARs
if (($_POST[fname]=="") || ($_POST[lname]=="") || ($_POST[question1]=="") || ($_POST[question2]=="") || ($_POST[question3]==""))
// This tells the code where to go if any of the top fields are missing values
{
header("Location: assignment2.html");
exit;
}
// Question1 results
if ($_POST[question1]=="8")
{
$result1=10;
} else {
$result1=0;
}
// Question2 results
if ($_POST[question2]=="15")
{
$result2=10;
} else {
$result2=0;
}
// Question3 results
if ($_POST[question3]=="a")
{
$result3=10;
} else {
$result3=0;
}
?>
<html>
<!-- Output page -->
<head>
<title>Quiz Results</title>
</head>
<body>
<?
$final=$result1 + result2 + result3;
echo "$_POST[fname] $_POST[lname] received $final</p>";
?>
</body>
</html>I can only seem to get the $result1 to work, but $result2 and $result3 will not add up at all. Not sure if i'm doing it correctly, thanks =\
JCART | Please use
Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]