tabatsoy Posted March 25, 2008 Share Posted March 25, 2008 when i press on the submit button the form still stays, what is the correct code when i press on the submit button the form will disappear and the thank you message will appear? here is my code: <FORM name ="form1" method ="post" action ="mathexam.php"> <table width="800" border="0" align="center" class="underresult"> <? $query = "SELECT * FROM mathquestions"; $result = mysql_query($query); for($i = 0; $i < mysql_num_rows($result); $i++){ $question_number ++; $question = mysql_result($result, $i, "question"); $choiceA = mysql_result($result, $i, "choiceA"); $choiceB = mysql_result($result, $i, "choiceB"); $choiceC = mysql_result($result, $i, "choiceC"); $choiceD = mysql_result($result, $i, "choiceD"); $answer = mysql_result($result, $i, "answer"); $selected_radio = $_POST[$question_number]; if ($selected_radio == $answer) { $score ++; } $result2 = mysql_query("update examinee set math = '".$score."' where firstname = '".$_SESSION['bago']."' and lastname = '".$_SESSION['bago2']."'"); $mathtotal = $score; echo '<tr> <td></td>'; '</tr>'; echo '<tr> <td> </td>'; '</tr>'; echo '<tr> <td width = "20" align = "left" valign = "top"><font class = "questions">'.$question_number.'.</span><td>'; echo '<td width = "280" align = "left" valign = "top" ><font class = "questions">'.$question.'</span></td>'; echo '<td width = "125" align = "left" valign = "center" > </td>'; echo '<td width = "125" align = "left" valign = "center" > </td>'; echo '<td width = "125"align = "left" valign = "center" > </td>'; echo '<td width = "125" align = "left" valign = "center" > </td></tr>'; echo '<tr> <td> </td>'; '</tr>'; echo '<tr> <td width = "20" align = "left" valign = "top"><td>'; echo '<td width = "280" align = "left" valign = "center" > </td>'; echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceA.'" />'.$choiceA.'</span></td>'; echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceB.'" />'.$choiceB.'</span></td>'; echo '<td width = "125"align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceC.'" />'.$choiceC.'</span></td>'; echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceD.'" />'.$choiceD.'</span></td></tr>'; echo '<tr> <td colspan = "7" class = "exam"> </td> </tr>'; } if($mathtotal > 0){ echo '<font class = "classified">~ End of Math exam. ~ <br>Your grades have been sumitted.</font><br><br> <a href = "englishexam.php"><input name="Button" type="button" value="Next" /></a><br><br>'; exit; } ?> </table> <br /><br /> <table width="240" border="0" align="center" class="session"> <tr> <td> <Input type = "Submit" Name = "Submit" VALUE = "Submit"></td> </tr> </table> <br /> </FORM> Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/ Share on other sites More sharing options...
rhodesa Posted March 25, 2008 Share Posted March 25, 2008 I don't see any problems....try changing the submit button line to: <td> <input type="submit" name="Submit" value="Submit"></td> If that doesn't work, please post the generated HTML. aka load it up in a browser, do View Source, and copy/paste that here Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/#findComment-500359 Share on other sites More sharing options...
tabatsoy Posted March 25, 2008 Author Share Posted March 25, 2008 yes there's no problem. all i want is when i press on the submit button the form will be gone and only the thankyou message will appear, but when i press on the submit button, the submit button is gone but the form is still there. please help Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/#findComment-500388 Share on other sites More sharing options...
rhodesa Posted March 25, 2008 Share Posted March 25, 2008 Ah, I get it now...try this: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $query = "SELECT * FROM mathquestions"; $result = mysql_query($query); for($i = 0; $i < mysql_num_rows($result); $i++){ $question_number ++; $answer = mysql_result($result, $i, "answer"); $selected_radio = $_POST[$question_number]; if($_POST[$question_number] == $answer) { $score ++; } } $result2 = mysql_query("update examinee set math = '".$score."' where firstname = '".$_SESSION['bago']."' and lastname = '".$_SESSION['bago2']."'"); if($result2){ echo '<font class = "classified">~ End of Math exam. ~ <br>Your grades have been sumitted.</font><br><br> <a href = "englishexam.php"><input name="Button" type="button" value="Next" /></a><br><br>'; }else{ echo 'Error'; } exit; } ?> <FORM name ="form1" method ="post" action ="mathexam.php"> <table width="800" border="0" align="center" class="underresult"> <? $query = "SELECT * FROM mathquestions"; $result = mysql_query($query); for($i = 0; $i < mysql_num_rows($result); $i++){ $question_number ++; $question = mysql_result($result, $i, "question"); $choiceA = mysql_result($result, $i, "choiceA"); $choiceB = mysql_result($result, $i, "choiceB"); $choiceC = mysql_result($result, $i, "choiceC"); $choiceD = mysql_result($result, $i, "choiceD"); $answer = mysql_result($result, $i, "answer"); $selected_radio = $_POST[$question_number]; echo '<tr> <td></td>'; '</tr>'; echo '<tr> <td> </td>'; '</tr>'; echo '<tr> <td width = "20" align = "left" valign = "top"><font class = "questions">'.$question_number.'.</span><td>'; echo '<td width = "280" align = "left" valign = "top" ><font class = "questions">'.$question.'</span></td>'; echo '<td width = "125" align = "left" valign = "center" > </td>'; echo '<td width = "125" align = "left" valign = "center" > </td>'; echo '<td width = "125"align = "left" valign = "center" > </td>'; echo '<td width = "125" align = "left" valign = "center" > </td></tr>'; echo '<tr> <td> </td>'; '</tr>'; echo '<tr> <td width = "20" align = "left" valign = "top"><td>'; echo '<td width = "280" align = "left" valign = "center" > </td>'; echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceA.'" />'.$choiceA.'</span></td>'; echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceB.'" />'.$choiceB.'</span></td>'; echo '<td width = "125"align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceC.'" />'.$choiceC.'</span></td>'; echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number.'" type="radio" value="'.$choiceD.'" />'.$choiceD.'</span></td></tr>'; echo '<tr> <td colspan = "7" class = "exam"> </td> </tr>'; } ?> </table> <br /><br /> <table width="240" border="0" align="center" class="session"> <tr> <td> <Input type = "Submit" Name = "Submit" VALUE = "Submit"></td> </tr> </table> <br /> </FORM> Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/#findComment-500395 Share on other sites More sharing options...
tabatsoy Posted March 27, 2008 Author Share Posted March 27, 2008 Good Day McGyver!!!! Sori for the late reply. I copy pasted you're code and the output is : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\wamp\www\exam\dummy.php on line 32 Please help me with my codes. Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/#findComment-502159 Share on other sites More sharing options...
rhodesa Posted March 27, 2008 Share Posted March 27, 2008 change this: $result = mysql_query($query); to this: $result = mysql_query($query) or die("Query error: ".mysql_error()); and let me know what it says Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/#findComment-502347 Share on other sites More sharing options...
tabatsoy Posted March 28, 2008 Author Share Posted March 28, 2008 it says there's no database selected. thanks McGyver UR THE MAN!!! its working now hope you'll help me again in my future questions! ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D Link to comment https://forums.phpfreaks.com/topic/97799-form-problem/#findComment-502755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.