Jump to content

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

actually i entered wrong answer. If it is wrong answer, i want it to say wrong or right.

 

3*2 = 6 but i said 3

 

How can I say 3 is wrong answer. correct answer is 6.

 

Please help.

 

if ($_POST['one'] == 6) {
echo 'Correct';
}
else {
echo 'Incorrect';
}

Link to comment
https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397964
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.

Edited by jazzman1
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.