PDA

View Full Version : Help with simple php input type form



skeptical
April 13th, 2002, 21:51
<html>
<body>
<?
$Q[0] = "Your name is:";
$real[0] = "bob";
$Q[1] = "Your age is:";
$real[1] = "200";

if(!isset($yourans[0]))
{
print("<form method=post action=$PHP_SELF>");
for($i = 0; $i < 2; $i++)
{
print($Q[$i]);
print("<input type=text name=\"$yourans[$i]\" value=\"$yourans[$i]\"> <br>");
}
print("<input type=submit value='Submit'></form>");
}
else
{
for($i = 0; $i < 2; $i++)
{
print($Q[$i]);
print("<br>Your answer:<br> ");
print($yourans[$i]);
if($yourans[$i] == $real[$i]) print("<br>Correct!");
else print("<br>Wrong!");
}

}

?>




The above is a simple php inputting thingy I'm making. I want a user to type in their and age. Then when they click submit, it will output whether they are Correct or Wrong. However, when I tried this, it doesnt come out right.

example input:
name: bob
age: 90

Your name is:
Wrong!
Your age is: 9
0
Wrong!

???? any help???

Mika
April 13th, 2002, 21:55
And how the code will know if they are correct or wrong? :confused: :confused: !!!! For me the output is correct , it's the idea that has no sense! If I understood well!!!!:confused:

skeptical
April 13th, 2002, 22:00
Originally posted by Mika
And how the code will know if they are correct or wrong? :confused: :confused: !!!! For me the output is correct , it's the idea that has no sense! If I understood well!!!!:confused:

well, say if a user enter: "bob" in the first Question. it will say correct. otherwise, it will say Wrong!

any???