Jump to content

form problem


tabatsoy

Recommended Posts

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

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

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

it says there's no database selected.

;D

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        ;D ;D ;D

          ;D              ;D        ;D        ;D ;D      ;D ;D  ;D    ;D ;D          ;D

          ;D              ;D ;D ;D ;D        ;D  ;D      ;D  ;D        ;D ;D          ;D ;D ;D

          ;D              ;D        ;D      ;D ;D ;D    ;D      ;D    ;D  ;D                ;D

          ;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

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.