Welcome to WebmasterWorld Guest from 54.146.55.156

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php/mysql

Trying to UPDATE with variables from form

     
11:29 am on Oct 29, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Hello all.

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";

Thanks

11:39 am on Oct 29, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:May 21, 2002
posts:120
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 6, 2001
posts:2213
votes: 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.

cheers

12:35 pm on Oct 29, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Maybe this line would help :o

mysql_query($query);

Now I feel like a total moron!

Thanks for jumping in to help me;)

12:47 pm on Oct 29, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 6, 2001
posts:2213
votes: 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