OK, there are several things wrong with your code, but because it's would be to lengthy to explain the errors, I spent some time creating a code that will work. You will need to create a few tables to generate dynamic content first:
# phpMyAdmin MySQL-Dump
# version 2.5.1
#
http://www.phpmyadmin.net/ (download page)
#
# Host: localhost
# Generation Time: Sep 07, 2007 at 09:23 PM
# Server version: 4.0.13
# PHP Version: 4.3.6
# Database : `forumtest`
# --------------------------------------------------------
#
# Table structure for table `itemtbl`
#
# Creation: Sep 07, 2007 at 09:18 PM
# Last update: Sep 07, 2007 at 09:18 PM
#
CREATE TABLE `itemtbl` (
`id` int(11) NOT NULL auto_increment,
`price` varchar(255) NOT NULL default '',
`purchaseqty` int(11) NOT NULL default '0',
`product` varchar(255) NOT NULL default '',
`date` date NOT NULL default '0000-00-00',
`name` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
#
# Dumping data for table `itemtbl`
#
INSERT INTO `itemtbl` VALUES (1, '12345', 5, 'product1', '2007-09-07', 'name1');
# --------------------------------------------------------
#
# Table structure for table `name`
#
# Creation: Sep 07, 2007 at 05:55 PM
# Last update: Sep 07, 2007 at 05:56 PM
#
CREATE TABLE `name` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;
#
# Dumping data for table `name`
#
INSERT INTO `name` VALUES (1, 'name1');
INSERT INTO `name` VALUES (2, 'name2');
INSERT INTO `name` VALUES (3, 'name3');
INSERT INTO `name` VALUES (4, 'name4');
INSERT INTO `name` VALUES (5, 'name5');
# --------------------------------------------------------
#
# Table structure for table `product`
#
# Creation: Sep 07, 2007 at 05:41 PM
# Last update: Sep 07, 2007 at 05:52 PM
#
CREATE TABLE `product` (
`id` int(11) NOT NULL auto_increment,
`product` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;
#
# Dumping data for table `product`
#
INSERT INTO `product` VALUES (1, 'product1');
INSERT INTO `product` VALUES (2, 'product2');
INSERT INTO `product` VALUES (3, 'product3');
INSERT INTO `product` VALUES (4, 'product4');
INSERT INTO `product` VALUES (5, 'product5');
# --------------------------------------------------------
#
# Table structure for table `qty`
#
# Creation: Sep 07, 2007 at 05:51 PM
# Last update: Sep 07, 2007 at 08:58 PM
#
CREATE TABLE `qty` (
`qty` int(11) NOT NULL default '0',
`usedqty` int(11) NOT NULL default '0'
) TYPE=MyISAM;
#
# Dumping data for table `qty`
#
INSERT INTO `qty` VALUES (5, 5);
Then I created a page called forumForm.php
Here is the page code:
<?php require_once('Connections/phpForum.php'); ?>
<?php
error_reporting(E_ALL ^ E_NOTICE);
ob_start();
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
/////////////////////////////////////////////////
//Declare Variables
$qty= $_GET['qty'];
$purchaseqty = $_POST['purchaseqty'];
/////////////////////////////////////////////////////////////////////////////
mysql_select_db($database_phpForum, $phpForum);
$query_rs_qty = "SELECT * FROM qty";
$rs_qty = mysql_query($query_rs_qty, $phpForum) or die(mysql_error());
$row_rs_qty = mysql_fetch_assoc($rs_qty);
$totalRows_rs_qty = mysql_num_rows($rs_qty);
if($_POST["Submit"])
{
if (($row_rs_qty['usedqty']) < ($row_rs_qty['qty']))
{
$inventory = "UPDATE qty SET usedqty = usedqty + $purchaseqty ";
$inventory_result = mysql_query($inventory,$phpForum)
or die ("Couldn't update inventory");
}
if (($row_rs_qty['usedqty']) >= ($row_rs_qty['qty']))
{
echo "<b><i><font color =\"red\">We do not have enough inventory to perform this action! </font></i></b><br/>";
echo "<input type='button' name='Back' value='Back' onclick=\"self.location='forumForm.php'\" />";
exit;
}
}
if (((isset($_POST["MM_insert"])) && ($_POST["MM_insert"]) && (($row_rs_qty['usedqty']) < ($row_rs_qty['qty'])) == "orderform")) {
$insertSQL = sprintf("INSERT INTO itemtbl (price, purchaseqty, product, `date`, name) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['price'], "text"),
GetSQLValueString($_POST['purchaseqty'], "int"),
GetSQLValueString($_POST['product'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['name'], "text"));
mysql_select_db($database_phpForum, $phpForum);
$Result1 = mysql_query($insertSQL, $phpForum) or die(mysql_error());
$insertGoTo = "#";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_phpForum, $phpForum);
$query_rs_Product = "SELECT * FROM product";
$rs_Product = mysql_query($query_rs_Product, $phpForum) or die(mysql_error());
$row_rs_Product = mysql_fetch_assoc($rs_Product);
$totalRows_rs_Product = mysql_num_rows($rs_Product);
mysql_select_db($database_phpForum, $phpForum);
$query_rs_name = "SELECT * FROM name";
$rs_name = mysql_query($query_rs_name, $phpForum) or die(mysql_error());
$row_rs_name = mysql_fetch_assoc($rs_name);
$totalRows_rs_name = mysql_num_rows($rs_name);
mysql_select_db($database_phpForum, $phpForum);
$query_rs_itemtbl = "SELECT * FROM itemtbl";
$rs_itemtbl = mysql_query($query_rs_itemtbl, $phpForum) or die(mysql_error());
$row_rs_itemtbl = mysql_fetch_assoc($rs_itemtbl);
$totalRows_rs_itemtbl = mysql_num_rows($rs_itemtbl);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="orderform" name="orderform" method="POST" action="<?php echo $editFormAction; ?>">
<table width="606" border="1" bordercolor="#000066">
<tr>
<td width="102">Name</td>
<td width="68">Product</td>
<td width="87">Quanity</td>
<td width="156">Price</td>
<td width="159">Date</td>
</tr>
<tr>
<td><select name="name" id="name">
<option value=""></option>
<?php
do {
?>
<option value="<?php echo $row_rs_name['name']?>"><?php echo $row_rs_name['name']?></option>
<?php
} while ($row_rs_name = mysql_fetch_assoc($rs_name));
$rows = mysql_num_rows($rs_name);
if($rows > 0) {
mysql_data_seek($rs_name, 0);
$row_rs_name = mysql_fetch_assoc($rs_name);
}
?>
</select></td>
<td><select name="product" id="product">
<option value=""></option>
<?php
do {
?>
<option value="<?php echo $row_rs_Product['product']?>"><?php echo $row_rs_Product['product']?></option>
<?php
} while ($row_rs_Product = mysql_fetch_assoc($rs_Product));
$rows = mysql_num_rows($rs_Product);
if($rows > 0) {
mysql_data_seek($rs_Product, 0);
$row_rs_Product = mysql_fetch_assoc($rs_Product);
}
?>
</select></td>
<td><select name="purchaseqty" id="purchaseqty">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input name="qty" type="hidden" id="qty" value="<?php echo $row_rs_qty['qty']; ?>" />
<input name="usedqty" type="hidden" id="usedqty" value="<?php echo $row_rs_qty['usedqty']; ?>"/></td>
<td>$<input name="price" type="text" id="price" /></td>
<td> <input name="date" type="text" id="date" value="<? echo date("Y-m-d "); ?>"/></td>
</tr>
<tr>
<td colspan="5"><div align="center">
<input type="submit" name="Submit" value="Submit" />
<input name="Reset" type="reset" id="Reset" value="Reset" />
</div></td>
</tr>
</table>
<p> </p>
<input type="hidden" name="MM_insert" value="orderform">
</form>
</body>
</html>
<?php
mysql_free_result($rs_Product);
mysql_free_result($rs_name);
mysql_free_result($rs_itemtbl);
mysql_free_result($rs_qty);
ob_flush();
?>
You will need to create your connection string for your information in the file called at the top of the page
(<?php require_once('Connections/phpForum.php'); ?>)
This is what mine looks like:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_phpForum = "localhost";
$database_phpForum = "forumtest";
$username_phpForum = "your_user_name";
$password_phpForum = "your_password";
$phpForum = mysql_pconnect($hostname_phpForum, $username_phpForum, $password_phpForum) or trigger_error(mysql_error(),E_USER_ERROR);
?>
I have this working fine on my localhost.
Hope this helps you out or at least gets you headed in the correct direction!