I copied the following practice code from an Internet site. The 'Submit' isn't working properly. Why doesn't this statement work ? I saved the code as forms_5.php
if ($action == "true") { // doesn't work
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>forms_L5.php</title
>
</head>
<body>
<?
$q = array(2,0,1,2,2);
$q1_bad = array("is a container for integers only",
"name can start with a number",
"can contain words, sentences, integers");
$q2_bad = array("a container for strings",
"a mathematical approach to storing integers",
'$string[x]');
$q3_bad = array("CGI", "HTML", "PHP");
$q4_bad = array("HTML & CGI", "PHP", "HTML & PHP");
$q5_bad = array("sint", "intrand", "srand");
if ($action == "true") {
$right = 0;
print("Thank you for taking the PHP Quiz!");
if ($answer_1 == $q[0]) { $right++; }
if ($answer_2 == $q[1]) { $right++; }
if ($answer_3 == $q[2]) { $right++; }
if ($answer_4 == $q[3]) { $right++; }
if ($answer_5 == $q[4]) { $right++; }
$percentage = ($right / 5) * 100;
print("<p>You scored <strong>$percentage %</strong> on the quiz!</BODY></HTML>");
exit;
}
?>
<FORM METHOD="POST" ACTION="forms_5.php">
<input type="hidden" name="action" value="true">
Take the PHP Week 5 Quiz<p>
Question 1: A string is ... <br>
<input type="radio" value="0" name="answer_1"><? echo($q1_bad[0]); ?>
<input type="radio" value="1" name="answer_1"><? echo($q1_bad[1]); ?>
<input type="radio" value="2" name="answer_1"><? echo($q1_bad[2]); ?>
<br>Question 2: An array is ...
<select name="answer_2">
<option selected value="0"><? echo($q2_bad[0]); ?></option>
<option value="1"><? echo($q2_bad[1]); ?></option>
<option value="2"><? echo($q2_bad[2]); ?></option>
</select>
<br>Question 3: Building a form primarily requires ...
<input type="radio" value="0" checked name="answer_3"><? echo($q3_bad[0]); ?>
<input type="radio" value="1" name="answer_3"><? echo($q3_bad[1]); ?>
<input type="radio" value="2" name="answer_3"><? echo($q3_bad[2]); ?>
<br>Question 4: This script is an example of ...
<select name="answer_4">
<option selected value="0"><? echo($q4_bad[0]); ?></option>
<option value="1"><? echo($q4_bad[1]); ?></option>
<option value="2"><? echo($q4_bad[2]); ?></option>
</select>
<br>Question 5: Before generating random numbers you use ...
<input type="radio" value="0" name="answer_5"><? echo($q5_bad[0]); ?>
<input type="radio" value="1" name="answer_5"><? echo($q5_bad[1]); ?>
<input type="radio" value="2" name="answer_5"><? echo($q5_bad[2]); ?>
<p><center><input type="submit" value="Submit"> <input type="reset" value="Reset"></center>
</FORM>
</body>
</html>