Jump to content

Form Submit


phpgoal

Recommended Posts

Hi,

 

I am trying to do questions and answers in php. I am lost. I am new in php.

 

How do I score in FormS.php whether answer is correct or not?

 

--------------------------------------------------------------------------------

 

1. Form.php

 

<html>

<head>

 

<title>t</title>

</head>

 

<body>

 

 

<h1>t</h1>

 

<form name="lab5" method="post" action="formS.php">

<input type='hidden' name='ts' value='2012-12-06 09:46:51'> <table border="1" cellspacing="5" cellpadding="5">

 

<tr><td>3 * 2 </td><td><input type='text' size='2' name=one></td>

</tr>

<tr> <td>11 * 9 </td><td><input type='text' size='2' name=two></td>

</tr>

 

<tr><td colspan=6 align='right'><input type='submit' value='Score' name='btn_score'></td></tr>

 

</table>

 

<br />

<br />

 

 

</form>

<br />

<br />

 

 

 

 

 

</body>

</html>

 

 

2. FormS.php

 

 

<html>

<body>

<?php echo $_POST["one"]; ?><br>

<?php echo $_POST["two"]; ?>

</body>

</html>

 

 

Please help me .

Link to comment
https://forums.phpfreaks.com/topic/271675-form-submit/
Share on other sites

1. formS.php

 

<html>

<body>

<?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?>

 

 

<?php echo $_POST["one"]; ?><br>

<?php echo $_POST["two"]; ?>

</body>

</html>

 

 

 

2. running the script

 

I entered 3 and 4 then click score got the below:

 

Array

(

[ts] => 2012-12-06 09:46:51

[one] => 3

[two] => 4

[btn_score] => Score

)

 

3

4

 

Please help!!!!

Link to comment
https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397893
Share on other sites

Better approach of this is to create a nested or multidimensional array that includes the question and the answer.

In other words, you have to create a list, where each item in the list is another list, after that you need to compare that responze with the question's actual answer.

Link to comment
https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397973
Share on other sites

<html>

<body>

<?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?>

 

 

<?php

 

if ($_POST['one'] == 6) {

echo 'Correct';

}

else {

echo 'Incorrect';

}

 

 

?><br>

<?php

 

if ($_POST['two'] == 55)

 

{

echo 'Correct';

}

else {

echo 'Incorrect';

}

?>

</body>

</html>

 

 

Error:

 

Parse error: syntax error, unexpected '{' in /home/..... on line 6

Link to comment
https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397994
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.