PHP Project
|
We have a project about PHP... Please... Anyone... Tell me what is wrong with my code! I'm new regarding PHP, and I'm going nuts! Help! Our Professor required us to use arrays for this... Form Receiving PHP This project is an Online Exam, but I somehow cannot understand why the PHP script cannot get the answer from the form... Please Help... P.S. The submission of the project shall be on 27th of March, 2006. I'm not demanding/pressuring you, though. Any help will be appreciated! |
Re: PHP Project
Link |
by
![]() |
i could help better if you showed me the file source. it looks like you have an "else" somewhere unexpected. my guess is you either forgot some close curly braces. ![]() ![]() ![]() |
Re: PHP Project
|
Okay, I'll post the code of PHP script: ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); $q1[0]="wrong"; $q1[1]="correct"; $q2[2]="correct"; $q2[3]="wrong"; ?> { if ($q1a==wrong) { print "{$_POST['q1']} Wrong, there are only three. n"; } else { print 'Correct!'; } } if ($q2[$_POST['q2']]==correct) { print 'Correct! n'; } else { print 'Wrong, it is.'; } ?> Here it is... Thanks Gendou-sama. *edit Why is it that the opening tag of the PHP doesn't show up? |
Re: PHP Project
Link |
by
![]() |
ok, first of all, since you arent using a template system, just put it all in one file. second, you should NEVER give away the answers in the HTML, anyone can view the source! third, PHP has an array notation, use it! <?php ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE); if($_POST) { $answers = array( 1 => array( 1 => "Wrong, there are only three.", 0 => "Correct!" ), 2 => array( 1 => "Correct!", 0 => "Wrong, this is a true statement." ) ); foreach($answer as $index => $answer) { print("Question $index:" . $answer[$_POST["question_$index"]] . "<br />n"); } exit(); // do not print the HTML below } ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Form</title> </head> <body bgcolor="#bda88b" text="#ffffff"> <font face="arial, helvetica, sans serif" size="2"><br /> <big>Please answer 5 science questions then enter your name, comment about the program, then click submit:</big><br /> <hr align="left" style="border-style:dashed; width:50%;"><br /> <!--Radio Buttons Here--> <form method="post" /> 1. There are four types of muscles. True or False? <br /> <input type="radio" name="question_1" value="1" /> True <br /> <input type="radio" name="question_1" value="0" /> False <br /> <br /> 2. Diencephalon is superior to the midbrain and between two cerebral hemispheres. True of False? <br /> <input type="radio" name="question_2" value="1" /> True <br /> <input type="radio" name="question_2" value="0" /> False <br /> <input type="submit" name="submit" value="submit" /> </form> </font> </body> </html> ![]() ![]() ![]() |