phpgoal Posted December 6, 2012 Share Posted December 6, 2012 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 . Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/ Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 Put this line of code on the top of FormS.php file and show us the results: <?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397866 Share on other sites More sharing options...
phpgoal Posted December 6, 2012 Author Share Posted December 6, 2012 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!!!! Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397893 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 I don't get it, everything is just fine! What result do you want to output? Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397895 Share on other sites More sharing options...
phpgoal Posted December 6, 2012 Author Share Posted December 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397896 Share on other sites More sharing options...
Christian F. Posted December 6, 2012 Share Posted December 6, 2012 I think you'd benefit from starting here, should help you get started. Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397938 Share on other sites More sharing options...
phpgoal Posted December 6, 2012 Author Share Posted December 6, 2012 I will. Can you please help me with my problem for now? Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397955 Share on other sites More sharing options...
mrMarcus Posted December 6, 2012 Share Posted December 6, 2012 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397964 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 (edited) 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 December 6, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397973 Share on other sites More sharing options...
Christian F. Posted December 6, 2012 Share Posted December 6, 2012 Basic mathematics would be more than sufficient for this. You have three variables, two of which needs to be multiplied with each other to match the third. Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397978 Share on other sites More sharing options...
phpgoal Posted December 6, 2012 Author Share Posted December 6, 2012 <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 Quote Link to comment https://forums.phpfreaks.com/topic/271675-form-submit/#findComment-1397994 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.