Well, it seems to me that if these two happen within the same scope level (same 
function, same class) which I cannot verify based on what you gave us, the $fgNumber 
should not be empty. Therefore I'd bet there's some code in between that reinitializes 
$fgNumber or the update is in a function that does not have access to the $fgNumber. 
You can give a function access to that variable by declaring it global inside of the 
function, or passing it as a variable.

<>< Ryan

-----Original Message-----
From: Michael Knauf/Niles [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 1:41 PM
Subject: Re: [PHP-DB] What's wrong with my update query select works,
but update doesn't?

Here's the code: with some extraneous html removed to make it easier to

<? 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 */
 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


if ($tableid=="products") {
echo "updating products";
      if ($productName !=""  and  $productDescription !="") {
      $products_query= "UPDATE products SET productName='$productName',
productDescription='$productDescription' where fgNumber='$fgNumber' limit
      $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());
<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="
                        <td colspan="4"><h2>Products Table</h2>
                        <input name="productId" type="text" id="productId"
value="<? echo $productsRow['id'] ?>" size="5"></td>
                                    <input name="fgNumber" type="text" id
="fgNumber" value="<? echo $productsRow['fgNumber'] ?>" size="10"></td>
                                    <input name="productName" type="text"
id="productName" value="<? echo $productsRow['productName'] ?>" size
                                    <input name="productDescription" type
="text" id="productDescription" value="<? echo $productsRow
['productDescription'] ?>" size="48"></td>
                        <td colspan="4">Update Product Information
                        <input type="submit" name="Submit" value

I keep looking for an error and not finding one, am I missing something


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to