I am trying to create an inventory page to keep track of printer consumbles. The page uses html, Php and a MySQL database.
I am able to query the database for the current inventory and display it in a table. The user then enters an inventory id (which is just an auto-incrementing if field in the database) and that variable is passed to a php script that brings up that record for updating. That part works fine, which tells me that it is passing the 'uid' variable without any problems, using $_GET.
However, when I try to update any changes to the fields, it does not pass the variables. I added a line to the second update page (update2.php) to display the query, but it is only displaying empty fields. I am fairly new to Php, so my guess is that I am missing something simple.
Any help is GREATLY appreciated. Thanks!
update1.php (This page displays the selected record in text boxes, allowing user to update info, then submits to update2.php)
<?php
//Define variables
$ud_id=$_REQUEST['uid'];
//Set the variables for database access
$User="***";
$Password="***";
$DBName="inventory";
$TableName="consumables";
print ("<form action=\"update2.php\" method=POST>\n");
$Link=mysql_connect (localhost, $User, $Password);
$Query="SELECT * from $TableName WHERE id='$ud_id'";
$Result=mysql_db_query ($DBName, $Query, $Link);
// Create table
while ($Row=mysql_fetch_array($Result)){
print ("<table width=\"25%\" frame=box rules=none border=2 bgcolor=\"#0bbfff\" cellpadding=3 cellspacing=3 align=center>\n");
print ("<tr>\n");
print ("<th align=center><h3>Inventory ID</h3></th><th align=center><h3>$Row[id]</h3></th>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td align=left><b>Printer Make</b></td><td align=center><input type=text value=$Row[printermake]></td>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td align=left><b>Printer Model</b></td><td align=center><input type=text value=$Row[printermodel]></td>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td align=left><b>Item</b></td><td align=center><input type=text value=$Row[item]></td>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td align=left><b>Part Number</b></td><td align=center><input type=text value=$Row[partnumber]></td>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td align=left><b>Quantity</b></td><td align=center><input type=text value=$Row[quantity]></td>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td></td>\n");
print ("</tr>\n");
print ("<tr>\n");
print ("<td></td>\n");
print ("<tr>\n");
print ("<td align=center colspan=2><input type=SUBMIT name=\"Submit\" value=\">> Update Record <<\"></td>\n");
print ("</tr>\n");
print ("</table>\n");
}
mysql_close ($Link);
$id=$Row[id];
$printermake=$Row[printermake];
$printermodel=$Row[printermodel];
$item=$Row[item];
$partnumber=$Row[partnumber];
$quantity=$Row[quantity];
?>
</form>
</html>
update2.php (This is the page that actually submits changes to the database)
<?php
//Define variables
$ud_id=$REQUEST['$id'];
$ud_printermake=$REQUEST['printermake'];
$ud_printermodel=$REQUEST['printermodel'];
$ud_item=$REQUEST['item'];
$ud_partnumber=$REQUEST['partnumber'];
$ud_quantity=$REQUEST['quantity'];
//Set the variables for database access
$User="***";
$Password="***";
$DBName="inventory";
$TableName="consumables";
$Link=mysql_connect (localhost, $User, $Password);
$Query="UPDATE $TableName SET printermake='$printermake', printermodel='$printermodel', item='$item', partnumber='$partnumber',
quantity='$quantity' WHERE id='$ud_id'";
print ("The query is: <BR><BR>$Query<p>\n");
if (mysql_db_query ($DBName, $Query, $Link)){
print ("<br><br><br>\n");
print ("<center>\n");
print ("The inventory has been successfully updated!<br>\n");
print ("<br><br><br>\n");
print ("<a href=\"http://10.104.7.149/inventory/inventory_all.php\">Return to inventory</a>\n");
print ("</center>\n");
}else{
print ("<br><br><br>\n");
print ("<center>\n");
print ("!!! There was a problem updating the inventory !!!<br>\n");
print ("<br><br><br>\n");
print ("<a href=\"http://10.104.7.149/surveys/helpdesk/hdadminpage.html\">Return to Help Desk Admin Home Page</a>\n");
print ("</center>\n");
}
mysql_close ($Link);
?>
</html>