Here's the code: with some extraneous html removed to make it easier to
read...
<? require('connect.php') ?>
<?
/* check for a request to display a new fg number and if so make sure the
data is good
if the fg number is good it is used for all other data queries */
$fgNumber="";
if ($switchfg !==""){
$switchfg = htmlentities($switchfg , ENT_QUOTES);
if (strlen($switchfg) > 7) {
echo "bad fg number";
}
else {
$fgNumber =$switchfg ;
echo $fgNumber;
}}
?>
This works... I added the echo statement in the last line for debugging
purposes, the page does indeed display the fgNumber, and uses the variable
to perform other queries, which also work... until I try to update the
database
<?
if ($tableid=="products") {
echo "updating products";
if ($productName !="" and $productDescription !="") {
$products_query= "UPDATE products SET productName='$productName',
productDescription='$productDescription' where fgNumber='$fgNumber' limit
1";
$productsResult = mysql_query($products_query);
echo $products_query;
}
}
?>
Again, that last line is a debugging entry, and it echoes back the query
I'm expecting, except that the variable $fgNumber looses it's value
somewhere and the query looks like this:
UPDATE products SET productName='ZR-4630 MultiZone Receiver',
productDescription='4-Source 6-Zone Receiver with AM/FM Tuner' where
fgNumber='' limit 1
I expect it to say " where fgNumber='FG00813"
Here's the form that triggers the update
<!-- ______________________________________ PRODUCTS TABLE
______________________________________ -->
<?
$productsQuery ="SELECT id, fgNumber, productName, productDescription FROM
products where fgNumber='$fgNumber' ";
$productsRecordset = mysql_query($productsQuery) or die(mysql_error());
$productsRow=mysql_fetch_array($productsRecordset);
//$fgNumber=$productsRow['fgNumber']
?>
<form name="products" method="post" action="<? $_SERVER['php_self']
?>"><input name="tableid" type="hidden" value="products">
<table width="100%" border="0" cellpadding="10" cellspacing="0" bgcolor="
#CCCCCC">
<tr>
<td colspan="4"><h2>Products Table</h2>
<hr>
</td>
</tr>
<tr>
<td>ID:
<input name="productId" type="text" id="productId"
value="<? echo $productsRow['id'] ?>" size="5"></td>
<td>FG#:
<input name="fgNumber" type="text" id
="fgNumber" value="<? echo $productsRow['fgNumber'] ?>" size="10"></td>
<td>Name:
<input name="productName" type="text"
id="productName" value="<? echo $productsRow['productName'] ?>" size
="36"></td>
<td>Description
<input name="productDescription" type
="text" id="productDescription" value="<? echo $productsRow
['productDescription'] ?>" size="48"></td>
</tr>
<tr>
<td colspan="4">Update Product Information
<input type="submit" name="Submit" value
="Submit"></td>
</tr>
</table>
</form>
I keep looking for an error and not finding one, am I missing something
obvious?
Michael
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php