Trying to UPDATE with variables from form
| 11:29 am on Oct 29, 2002 (gmt 0)|
I'm trying to set up a page where my client can enter info about new items that I add to the db.
I'm passing the variables through a form to the edit_item.php page. For some reason, the db will not update. I checked to see if the vars were passed ok by using echo statements with them after the db query and they go through fine. Can someone look at this and see what I have wrong, please?
|$query = "UPDATE `prod` SET |
`item_no` = $item_no,
`name` = $name,
`desc1` = $desc,
`desc2` = NULL ,
`width` = NULL ,
`height` = NULL ,
`included` = $included,
`weight` = NULL ,
`stock` = NULL ,
`price` = $price
WHERE `prod_id` = $old_no LIMIT 1";
| 11:39 am on Oct 29, 2002 (gmt 0)|
Try changing the query to
$query = "UPDATE prod SET
item_no = '$item_no',
name = '$name',
desc1 = '$desc',
desc2 = 'NULL' ,
width = 'NULL' ,
height = 'NULL' ,
included = '$included',
weight = 'NULL' ,
stock = 'NULL' ,
price = '$price'
WHERE prod_id = '$old_no' LIMIT 1";
The quote should go around the data and not the field names and table names. Based on what you typed above your query probably looked like
UPDATE 'prod' SET 'item_no' = 35 ....
it should look like
UPDATE prod SET item_no = '35' ....
| 12:01 pm on Oct 29, 2002 (gmt 0)|
Thanks shanz. Unfortunately, it still won't work:(
I'm sure my connect statements are right and the variables are passed. This is driving me crazy.
| 12:27 pm on Oct 29, 2002 (gmt 0)|
Just a few comments that might make a difference.
I would guess that "name" is restricted SQL keyword
Do your fields allow NULL
I have had problems of this sort with the quotes etc. Numbers dont require them and text does. I have spent some time before finding these things out by trial and error.
Hope you get it sorted.
| 12:35 pm on Oct 29, 2002 (gmt 0)|
Maybe this line would help :o
Now I feel like a total moron!
Thanks for jumping in to help me;)
| 12:47 pm on Oct 29, 2002 (gmt 0)|
LOL I have done that exact thing myself :)
I learnt fast to look for my home grown moronic mistakes
Glad you got it sorted