I am going crazy trying to edit/update table records. Basically, I want to give the users the opportunity to edit records they submitted via a form to a database.
My scripts look something like this "
.
.
.
.
<?
include("/xampp/htdocs/dbinfo.inc.php");
// variable declaration
$emp_no=$POST['emp_no'];
$job_id=$POST['job_id'];
$pic_loc=$POST['pic_loc'];
$lines=$POST['lines'];
$order_type=$POST['order_type'];
$packlist_number=$POST['packlist_number'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die(mysql_error());
$sql = "SELECT * FROM test1 WHERE emp_no = '$emp_no' AND Job_id = '$job_id' AND pick location = '$pic_loc' AND packlist_number = '$packlist_number'";
$result = mysql_query($sql);
$num=mysql_num_rows($result);
if($num>=1) {
?>
<font size = +2 color="#ff3333">
<?
echo "SORRY! THIS PACKLIST WAS SUBMITTED ALREADY!<br>";
echo "THE INFORMATION WAS NOT ENTERED AGAIN!";
?>
</FONT>
<?
} else {
$sql = "INSERT INTO test1 VALUES ('','$emp_no','$job_id','$pic_loc','$lines','$order_type','$packlist_number', NOW())";
mysql_query($sql);
mysql_close();
?>
<font color="green">
<?
echo "CONGRATULATIONS! YOUR INFORMATION WAS ENTERED SUCCESSFULLY!<BR><br>\n";
?>
</font>
<?
echo "You submitted the following data!<br><br>\n";
?>
<FONT FACE="ARIAL" SIZE=4 COLOR="#000080">
<table border="1" cellspacing="10%" summary="">
<tr>
<td>
<?
echo "Employee Number"; ?> </td><td><? echo $emp_no; ?></td>
</tr>
<tr>
<td>
<?
echo "Job_id"; ?></td><td><? echo $job_id; ?></td>
</tr>
<tr>
<td>
<?
echo "Pick Location"; ?></td><td><? echo $pic_loc; ?></td>
</tr>
<tr>
<td>
<?
echo "Amount"; ?></td><td><? echo $lines; ?></td>
</tr>
<tr>
<td>
<?
echo "Order Type"; ?></td><td><? echo $order_type; ?></td>
<tr>
<td>
<?
echo "Packlist Number"; ?></td><td><? echo $packlist_number; ?></td>
</tr>
<tr>
<td>
<?
echo "Edit"; ?></td><td><? echo "<A HREF=\"production3c_update.php?id=$id\">"; ?>EDIT</A></TD>
</table><p>
</FORM>
<?
}
?>
</BODY>
</HTML>
=================================
include("dbinfo.inc.php");
// variables from form
$id =$POST['id'];
$emp_no=$POST['emp_no'];
$job_id=$POST['job_id'];
$pic_loc=$POST['pic_loc'];
$lines=$POST['lines'];
$order_type=$POST['order_type'];
$packlist_number=$_POST['packlist_number'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die(mysql_error());
$query="SELECT * FROM test1 WHERE id = '$id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$emp_no=mysql_result($result,$i,"emp_no");
$job_id=mysql_result($result,$i,"job_id");
$pic_loc=mysql_result($result,$i,"pic_loc");
$lines=mysql_result($result,$i,"lines");
$order_type=mysql_result($result,$i,"order_type");
$packlist_number=mysql_result($result,$i,"packlist_number");
?>
<form action="production_updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>"><br>
Employee Number <input type="data" name="ud_emp_no" value="<? echo $emp_no; ?>"><br>
Job ID <input type="data" name="ud_job_id" value="<? echo $job_id; ?>"><br>
Pick location ID <input type="data" name="ud_pic_loc" value="<? echo $pic_loc; ?>"><br>
Amount <input type="data" name="ud_lines" value="<? echo $lines; ?>"><br>
Order Type <input type="text" name="ud_order_type" value="<? echo $order_type; ?>"><br>
Packlist Number <input type="data" name="ud_packlist_number" value="<? echo $packlist_number; ?>"><br>
<input type="Submit" value="Update">
</form>
<?
++$i;
}
?>
<P>
<CENTER><A HREF = "production3a.html">RETURN TO FORM!</A></CENTER>
</BODY>
</HTML>
For some reason when I press the 'edit' link it doesn't grab the id of the record in the url.
What am I doing wrong?
Thanks in advance