Jump to content


Photo

Submit Button Not Working


  • Please log in to reply
3 replies to this topic

#1 ashrafzia

ashrafzia
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 28 September 2006 - 12:31 AM

THe submit button in the following code isn't working. i am redirected to the same page (student.php) when i press the submit button.

if (isset($_POST['addstudent_x'])) {
$registration_form = "<form method=\"post\" action=\"student_records.php\" name='registration_form'>
					<table border='0' align='center' cellspacing='8' cellpadding='2'>
					<tr><td>ID :</td><td><input type='text' name='id' size='1'></td></tr>
					<tr><td>Name :</td><td><input type='text' name='name'></td></tr>
					<tr><td>Father's Name :</td><td><input type='text' name='father_name'></td></tr>
					<tr><td>Gender :</td><td>Male<input type='radio' value='Male' name='gender'>
					    					 Female<input type='radio' value='Female' name='gender'></td>
					</tr>
					<tr><td>Address :</td><td><input type='text' name='address' size='50'></td></tr>
					<tr><td colspan='2' align='center'><input type='submit' name='submit'></td></tr>
					</table>
					</form>";
}

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 September 2006 - 12:35 AM

Assuming that you echo $registration_form, what you describe as happening doesn't make sense since the registration form action is obviously student_records.php.  I wonder if there's a logic flaw in code we're not seeing here?
Legend has it that reading the manual never killed anyone.
My site

#3 ashrafzia

ashrafzia
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 28 September 2006 - 12:41 AM

Assuming that you echo $registration_form, what you describe as happening doesn't make sense since the registration form action is obviously student_records.php.  I wonder if there's a logic flaw in code we're not seeing here?


I think things should be clear to you now :) Here's the full coding :

<?php

if (isset($_POST['students_x'])){
$students = "<form method='post' action='student.php' name='students_form'>
		 <table border='0'>
		 <tr><td><input type='image' src='images/addstudent.gif' name='addstudent'></td></tr>
		 <tr><td><input type='image' src='images/editstudent.gif' name='editstudent'></td></tr>
		 <tr><td><input type='image' src='images/deletestudent.gif' name=deletestudent'></td></tr>
		 <tr><td><input type='image' src='images/viewallstudents.gif' name='viewallstudent'></td></tr>
		 </table>
		 </form>";
}

if (isset($_POST['addstudent_x'])) {
$registration_form = "<form method=\"post\" action=\"student_records.php\" name='registration_form'>
					<table border='0' align='center' cellspacing='8' cellpadding='2'>
					<tr><td>ID :</td><td><input type='text' name='id' size='1'></td></tr>
					<tr><td>Name :</td><td><input type='text' name='name'></td></tr>
					<tr><td>Father's Name :</td><td><input type='text' name='father_name'></td></tr>
					<tr><td>Gender :</td><td>Male<input type='radio' value='Male' name='gender'>
					    					 Female<input type='radio' value='Female' name='gender'></td>
					</tr>
					<tr><td>Address :</td><td><input type='text' name='address' size='50'></td></tr>
					<tr><td colspan='2' align='center'><input type='submit' name='submit'></td></tr>
					</table>
					</form>";
}

if (isset($_POST['submit_registration_x'])){
include "connection.php";
$table_name = "registration";
$sql = "INSERT INTO $table_name (id, name, father_name, gender, address)
		VALUES ('$_POST[id]', '$_POST[name]', '$_POST[father_name]', '$_POST[gender]', '$_POST[address]')";
$result = @mysql_query($sql, $connection) or die (mysql_error());
$sql = "SELECT * from $table_name";
$result = mysql_query($sql, $connection) or die (mysql_error());
echo "<form method='post' action='student.php' name='student_records'>
	  <table border='1' cellspacing='4' cellpadding='2' align='center'>
	  <tr><th>ID</th><th>Name</th><th>Father's Name</th><th>Gender</th><th>Address</th></tr>";
//		$i=0;
while($row = mysql_fetch_array($result)){
	$id = $row['id'];
	$name = $row['name'];
	$father_name = $row['father_name'];
	$gender = $row['gender'];
	$address = $row['address'];
	$student_records[$i] = "<tr><td>$id</td><td>$name</td><td>$father_name</td><td>$gender</td><td>$address</td></tr>";
//	$i++;
	}
	echo "</table></form>";
}

?>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Examination System</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<body>
<form method="post" action="student.php">
  <table width="761" border="0">
    <tr>
      <td colspan="4"><img src="images/header.jpg" width="755" height="133"></td>
    </tr>
    <tr>
      <td width="169"><input type="image" src="images/students.gif" width="169" height="32" name="students"></td>
    </tr>
  </table>
  <p><?php echo "$registration_form"; ?><?php //echo "$student_records[$i]"; ?></p>
  <p><?php echo "$students"; ?></p>

</form>
</body>
</html>



#4 Fehnris

Fehnris
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 28 September 2006 - 07:45 AM

From looking at your registration form, I can not see a submit button called 'submit_registration_x' which you check further down with another if statement which looks like it enters a new student into the database.  Try renaming the submit button of the registration form to 'submit_registration_x'.

Also it looks like your nesting html forms which is a no no.  In your HTML at the bottom you open a form and dont close it before echoing out the $registration_form and $students.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users