Re: query problem
| From: | Stephen | Date: | Mon, 21 Oct 2002 21:19:23 +0000 |
| Subject: | Re: query problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120804@lists.php.net to get a copy of this message | ||
One thing I've noticed in the new version of PHP is it's not to be exact.
It's also nice to put your SQL in it's own varible. Taking what you have,
I'd put this:
$sql = "UPDATE products SET prod_name='$prod_name',
prod_sku='$prod_sku', prod_price='$prod_price',
prod_sdesc='$prod_sdesc',
prod_ldesc='$prod_ldesc', prod_cat='$prod_cat', itemnum='$itemnum',
assoc='$assoc', best_seller='$best_seller' where ID =
'$prod_ID'";
$conn = **YOUR DATABASE CONNECTION**
$query = mysql_query($sql, $conn);
if(!$query) { echo "Error running query<br>".mysql_error();
Hope that helps!
Thanks,
Stephen Craton
http://www.melchior.us
----- Original Message -----
From: "Jennifer Swofford" <jen@littleduck.com>
To: <php-general@lists.php.net>
Sent: Monday, October 21, 2002 4:05 PM
Subject: [PHP] query problem
I am in need of fresh eyes and brains. :)
I have a database full of products. The client needs to be able to update
the products in the database, so I set up a maintenance area for them to do
so. They are able to view the product details, edit the details, and then
submit the changes. All very standard, in a form, using php and mysql.
And it was working fine, or so I thought, until recently.
The client was doing a whole batch of updates... and it seems that the query
works for some items and not for others. For instance, I have a category
called "Auto and Garage", and of the 7 items in that category, only 1 is
updatable. In the "For the Birds" category, 12 of the 20 items are
updatable. It is always the same items that fail.
The page that does the editing is called edit_product.php, and the query
looks like this:
mysql_query("UPDATE products SET prod_name='$prod_name',
prod_sku='$prod_sku', prod_price='$prod_price',
prod_sdesc='$prod_sdesc',
prod_ldesc='$prod_ldesc', prod_cat='$prod_cat', itemnum='$itemnum',
assoc='$assoc', best_seller='$best_seller' where ID =
'$prod_ID'");
To test, I've added lines that echo each of those values, including $prod_ID
, which is the most important. (When I went to debug, I noticed that
$prod_ID was not in quotes, and then I added the quotes, but it still
doesn't work... I always forget the proper quoting convention.) And they
all echo just fine. It's trying to update the product with ID of 12, for
instance, and it echoes "12" for $prod_ID, and it seems like it has all the
right values... but the database ain't getting updated. Looking at the ID
numbers, and the rest of the field values, I can't see any pattern. (I was
hoping to find a problem with the items that had quotes, or that started
with the number "1", or some such... but no luck so far.)
Now, is it obvious to everyone what I'm overlooking here? Can anyone tell
me what else to do to try to debug this?
Eternal thanks in advance,
Jen