I need to be able to update multiple tables in a training database. Here is what I have done so far:
1. build a page to select the employee to update (TrainingUpdate.html)
2. after you select an employee you go to a page that lists and populates the current records in the database for that employee.(TrainingUpdate.php)
Here is my code so far:
TrainingUpdate.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Update Existing Employee Training Records</title>
<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon" />
</head>
<body>
<br>
<br>
<div id="container">
<div align="center">
<p>
<h1 align="center"><u><strong><font face="arial">Update Existing Employee Training Records</font></strong></u></h1>
</p>
</div>
<br>
<div id="select">
<br>
<br>
<div align="center">
<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
require_once("config.php");
$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("training_db");
$query="SELECT * FROM employee WHERE Emp_Id = \"".$formVars["Emp_Id"]."\"";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$formVars = array();
$formVars["FirstName"]=$row["FirstName"];
$formVars["LastName"]=$row["LastName"];
$formVars["Dept"]=$row["Dept"];
$formVars["Shift"]=$row["Shift"];
mysql_close($db1);
?>
<div align="center">
<form method="post" action="postupdate1.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="red">First Name:</font></td>
<td><input type="text" name="FirstName"
value="<? echo $formVars["FirstName"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Last Name:</font></td>
<td><input type="text" name="LastName"
value="<? echo $formVars["LastName"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Department:</font></td>
<td><input type="text" name="Dept"
value="<? echo $formVars["Dept"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Shift:</font></td>
<td><input type="text" name="Dept"
value="<? echo $formVars["Shift"]; ?>" size=50></td>
</tr>
</table>
<br>
<input type="submit" value="Submit">
</form>
</div>
<br>
<br>
<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
require_once("config.php");
$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("training_db");
$query="SELECT * FROM annual WHERE Emp_Id = \"".$formVars["Emp_Id"]."\"";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$formVars = array();
$formVars["harassment"]=$row["harassment"];
$formVars["bbp"]=$row["bbp"];
$formVars["loto"]=$row["loto"];
$formVars["hazcomm"]=$row["hazcomm"];
$formVars["ppe"]=$row["ppe"];
$formVars["evacuation"]=$row["evacuation"];
$formVars["drug"]=$row["drug"];
mysql_close($db1);
?>
<div align="center">
<form method="post" action="postupdate2.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="red">Harassment:</font></td>
<td><input type="text" name="harassment"
value="<? echo $formVars["harassment"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">BBP:</font></td>
<td><input type="text" name="bbp"
value="<? echo $formVars["bbp"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Loto:</font></td>
<td><input type="text" name="loto"
value="<? echo $formVars["loto"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Haz Comm:</font></td>
<td><input type="text" name="hazcomm"
value="<? echo $formVars["hazcomm"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">PPE:</font></td>
<td><input type="text" name="ppe"
value="<? echo $formVars["ppe"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Evacuation:</font></td>
<td><input type="text" name="evacuation"
value="<? echo $formVars["evacuation"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="red">Drug Free:</font></td>
<td><input type="text" name="drug"
value="<? echo $formVars["drug"]; ?>" size=50></td>
</tr>
</table>
<br>
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
<br>
<br>
<div align="center">
<div class="hovermenu">
<ul>
<li><a href="TrainingDataBaseSearch.php">Search Training</a></li>
<li><a href="TrainingDataBaseAdd.php">Add Training</a></li>
<li><a href="TrainingUpdate.html">Update Training</a></li>
<li><a href="../index.html">Home</a></li>
</ul>
</div>
</div>
<br>
</div>
<br>
<br>
</div>
<br>
</body>
</html>
postupdate1.php code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Updated Employee Records</title>
<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon" />
</head>
<body>
<div id="container">
<div align="center">
<p>
<h1 align="center"><u><strong><font face="arial">Updated Employee Records</font></strong></u></h1>
</p>
</div>
<br>
<div id="select">
<br>
<br>
<div align="center">
<?php
foreach($HTTP_POST_VARS as $varname => $value)
{
$formVars[$varname]=$value;
}
require_once("config.php");
$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("training_db");
echo "Congratulations the record has been successfully updated<br><br><a href=\"TrainingUpdate.html\">CLICK HERE</a><br><br>to update another record<br><br><br>";
$query = ("UPDATE `employee` SET FirstName=".$formVars["FirstName"].",
LastName=".$formVars["LastName"].",Dept=".$formVars["Dept"]."Shift=".$formVars["Shift"]." WHERE Emp_Id = '".$formVars["Emp_Id"]."'");
$query="UPDATE `employee` SET ".
"FirstName= \"".$formVars["FirstName"]."\",".
"LastName= \"".$formVars["LastName"]."\",".
"Dept= \"".$formVars["Dept"]."\"".
"Shift= \"".$formVars["Shift"]."\"".
"\" WHERE Emp_Id = \"".$formVars["Emp_Id"]."\"";
mysql_query($query);
mysql_close($db1);
?>
</div>
</div>
<br>
<br>
</div>
</body>
</html>
postupdate2.php code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Updated Employee Annual Training Records</title>
<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon" />
</head>
<body>
<div id="container">
<br>
<br>
<div align="center">
<p>
<h1 align="center"><u><strong><font face="arial">Updated Employee Annual Training Records</font></strong></u></h1>
</p>
</div>
<br>
<div id="select">
<br>
<br>
<div align="center">
<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
require_once("config.php");
$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("training_db");
echo "Congratulations the record has been successfully updated<br><br><a href=\"TrainingUpdate.html\">CLICK HERE</a><br><br>to update another record<br><br><br>";
$query="UPDATE annual SET ".
"harassment= \"".$formVars["harassment"]."\",".
"bbp= \"".$formVars["bbp"]."\",".
"loto= \"".$formVars["loto"]."\",".
"hazcomm= \"".$formVars["hazcomm"]."\",".
"ppe= \"".$formVars["ppe"]."\",".
"evacuation= \"".$formVars["evacuation"]."\",".
"drug= \"".$formVars["drug"]."\",".
"\" WHERE Emp_Id = \"".$formVars["Emp_Id"]."\"";
mysql_query($query);
mysql_close($db1);
?>
</div>
</div>
<br>
<br>
</div>
</body>
</html>
The way it's set up so far is you have to update each table one at a time. I would like to be able to update all the tables at once. The code for the selection of the employee (TrainingUpdate.html) and the page that lists the current data in the database for each employee (TrainingUpdate.php) work perfect but when I try to update it seems to update (no errors) and I get the Congratulations the record has been successfully updated message but it DOES NOT actually update the database. Thanks for any help..