Computing.Net > Forums > Web Development > Updating price list

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Updating price list

Reply to Message Icon

Name: AshTheIdiot
Date: December 12, 2006 at 13:58:53 Pacific
OS: Win XP Pro SP2
CPU/Ram: P4 3.2GHz, 1Gb Ram
Comment:

Hi, I'm having a bit of trouble editing the prices in a price list for a site I've created...

I've created the form and table for the actual prices to be typed in and sent to the processing page but I'm struggling to get them to actually work.

There's another page on the site where details of cars for sale can be changed and the query is simple enough since I'm editing the details for just one car. The problem with the pricelist is that I'm editing a number of entries in the table and I keep getting errors (Invalid query: 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 'WHERE p.id = '0'' at line 5) whenever I try to submit it. Any ideas how to get this working? The code in the process form is below...


foreach($price as $id => $price)
{
$sql = "UPDATE
pricelist p
SET
p.price = '$price',
WHERE
p.id = '$id'";

$result = mysql_query($sql) or die("Invalid query: ".mysql_error());
}



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: December 12, 2006 at 15:36:52 Pacific
Reply:

It always helps to see the FULL query when trying to debug. I will usually echo quries to the page during the development phase. Plus you could change your "on die" function as follows:

$result = mysql_query($sql) or die("The query:
".$sql."
Caused the following error:
".mysql_error());

If the full query is valid you will want to verify that the table and field names are exactlythe same as they are in the database. Plus, I am assuming that price and id are numeric fields int he database. In that case you can remove the single quotes from around the values. I don't think that will cause an error, but it might depending upon your version of MySQL.

Michael J


0
Reply to Message Icon

Related Posts

See More


RDP embed Ultimate Slideshow - Big ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Updating price list

Getting Search Listings Updated www.computing.net/answers/webdevel/getting-search-listings-updated/2780.html

'active' drop-down lists www.computing.net/answers/webdevel/active-dropdown-lists/2861.html

A couple of questions... www.computing.net/answers/webdevel/a-couple-of-questions/2948.html