0

I'm trying to update some info into database but for some reasons it doesn't update. Also I'm not getting error in the server logs.

mysql_query("UPDATE `view_item` SET
              `item_number` = $item_number,
              `title` = $title,
              `price` = $price,
              `shipping` = $shipping, 
              `location` = $location,
              `start_time` = $start_time,
              `end_time` = $end_time,
              `seller_userName` = $seller_userName,
              `seller_UserNum` = $seller_UserNum,
              `number_of_bids` = $number_of_bids,
              `picture_link` = $picture_link 
            WHERE `item_number` = $item_number");

5 Answers 5

2

you need to add quotes around your php variables

SET `item_numer` = '$item_number'

and so on. If that doesn't fix the problem. try running the query directly in MySQL and see what DB errors it throws.

Sign up to request clarification or add additional context in comments.

Comments

2

This question is too vague...

Run this after that query to see what's happening:

echo mysql_error();

Also, it's a great, useful habit to get your query in a variable and then run it, so you can see what it ultimately has before executing it:

$query = "UPDATE whatever";
// Here you can see what you'll be running
// echo $query;
mysql_query($query);

If you did this, you'd realize you're missing string quotes in your query.

2 Comments

I got the following error : <pre>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '9736364'' at line 1</pre> 9736364 is value of $item_number.
The lasted version of the query that i have is <pre> mysql_query("UPDATE view_item SET title = '$title', price = '$price', shipping = '$shipping', location = '$location', start_time = '$start_time', end_time = '$end_time', seller_userName = '$seller_userName', seller_UserNum = '$seller_UserNum', picture_link = '$picture_link WHERE item_number = '$item_number'"); </pre>
1

Seriously, use mysqli and parameterized queries.

Comments

1

The query is kinda off - you are trying to update item_number with $item_number, but also trying to limit the query to WHEREitem_number= $item_number. This wouldn't work if the new item number is different than the old one. Do you have access to the old item number? Or do you even need to update it?

1 Comment

indeed I just seen that I also update item_number with item_number so I removed this from the syntax but the rest of syntax is fine . Basically I'm trying to update the details(title, price, etc) related to the item_number.
0

I'm using

mysql_query("UPDATE view_item SET item_number = '$item_number', title = '$title', price = '$price', shipping = '$shipping', location = '$location', start_time = '$start_time', end_time = '$end_time', seller_userName = '$seller_userName', seller_UserNum = '$seller_UserNum', number_of_bids = '$number_of_bids', picture_link = '$picture_link' WHERE `item_number` = '$item_number'");

something like this and mine is working

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.