So I'm trying to create a PHP and MySQL program where users can add, update, delete, view and search records. But the problem is I can't update records whenever I click update button. Here's my code -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Update Record</title>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="5">
<form name="update category" method="POST" action="edit.php">
<tr>
<td> </td>
<td><strong>ID Number:</strong></td>
</tr>
<tr>
<td> </td>
<td >
<?php
include 'studentinfo_connect.php';
mysql_connect("$server", "$user", "$pass")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
$sql = mysql_query("SELECT ID FROM studentinfo_tbl ORDER BY ID");
$row = mysql_fetch_array($sql);
?>
<select name="ID">
<?php do{ ?>
<option value="<?php echo $row['ID']; ?>"><?php echo $row['ID']; ?> </option>
<?php } while($row = mysql_fetch_array($sql));?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Search"></td>
</tr>
</table>
<?php
include('studentinfo_connect.php');
mysql_connect("$server", "$user", "$pass")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
if(isset($_POST['submit']))
{
if (is_numeric($_POST['ID']))
{
$ID = $_POST['ID'];
$result = mysql_query("SELECT * FROM studentinfo_tbl WHERE ID=$ID")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
?>
</form>
<form name="update category" method="POST" action="edit.php">
<br /><label>ID Number: </label><input type="text" name="ID" value="<?php echo $row['ID']; ?>"/><br />
<br /><label>First Name: </label><input type="text" name="FN" value="<?php echo $row['FirstName']; ?>"/><br />
<br /><label>Last Name: </label><input type="text" name="LN" value="<?php echo $row['LastName']; ?>"/><br /><br />
<label>Year: </label>
<select name="Year" value="<?php echo $row['Year']; ?>"><br />
<br /><option value="1">First Year</option><br />
<br /><option value="2">Second Year</option><br />
<br /><option value="3">Third Year</option><br />
<br /><option value="4">Fourth Year</option><br />
</select><br />
<br /><label>Course: </label>
<select name="Course" value="<?php echo $row['Course']; ?>"><br />
<br /><option value="IT">BS Information Technology</option><br />
<br /><option value="HRM">BS Hotel and Restaurant Management</option><br />
<br /><option value="EDUC">BS Education</option><br />
</select><br />
<br /><input type="submit" value="UPDATE" name="sub" /><br /><br />
<?php
include('studentinfo_connect.php');
if (isset($_POST['sub']))
{
$ID = $_POST['ID'];
$result=mysql_query("UPDATE 'studentinfo_tbl' SET 'ID'=[ID], 'FirstName'=[FN], 'LastName'=[LN], 'Year'=[Year], 'Course'=[Course] WHERE 'ID'=$ID")
or die(mysql_error());
if(isset($result))
{
echo("<br>Record Updated!");
}
else
{
echo("Failed to Update Record!");
}
}
}
}
}
?>
</form>
</body>
</html>