Jump to content

Submit Button Not Working


ashrafzia

Recommended Posts

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.

[code]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>";[/code]
}
Link to comment
Share on other sites

[quote author=AndyB link=topic=109777.msg442782#msg442782 date=1159403740]
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?
[/quote]

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

[code]
<?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>

[/code]
Link to comment
Share on other sites

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.
Link to comment
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.