Update wont work...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
BigAbe
Forum Commoner
Posts: 66
Joined: Fri Mar 31, 2006 7:41 pm

Update wont work...

Post by BigAbe »

Aloha again everyone,

I have two similar queries (INSERT and UPDATE), and only the INSERT works...

Works:

Code: Select all

$runquery = mysql_query("INSERT INTO categories (catName) VALUES ('$catAdd')");
Does not Work:

Code: Select all

$runquery = mysql_query("UPDATE categories SET catActive = 0 WHERE catID = $catdeactivate)");
I have tried inputing the query directly into mySQL through phpMyAdmin, and the UPDATE query is performed perfectly.

I have debugged and ensured that the appropriate variables have been passed.

Any help would be awesome!

Mahalo,

-- Abe --
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What is $catdeactivate in this particular case?
BigAbe
Forum Commoner
Posts: 66
Joined: Fri Mar 31, 2006 7:41 pm

Post by BigAbe »

feyd wrote:What is $catdeactivate in this particular case?

Code: Select all

$catdeactivate=$_POST['catdeactivate'];
In this instance catdeactivate is an INT.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what does mysql_error() say?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you have a parse error

Code: Select all

$runquery = mysql_query("UPDATE categories SET catActive = 0 WHERE catID = $catdeactivate)");
should be

Code: Select all

$runquery = mysql_query("UPDATE categories SET catActive = 0 WHERE catID = '$catdeactivate'");
Notice you had an extra bracket and quote. Don't forgot to quote the strings as well.
tonera
Forum Newbie
Posts: 5
Joined: Mon Apr 10, 2006 10:40 pm

Post by tonera »

$runquery = mysql_query("UPDATE categories SET catActive = 0 WHERE catID = $catdeactivate)");

what's the red word?
BigAbe
Forum Commoner
Posts: 66
Joined: Fri Mar 31, 2006 7:41 pm

Post by BigAbe »

Jcart wrote:you have a parse error

Code: Select all

$runquery = mysql_query("UPDATE categories SET catActive = 0 WHERE catID = $catdeactivate)");
should be

Code: Select all

$runquery = mysql_query("UPDATE categories SET catActive = 0 WHERE catID = '$catdeactivate'");
Notice you had an extra bracket and quote. Don't forgot to quote the strings as well.
Thanks a million!

So in the future, I just need to keep spaces between all of the operators?

Thanks again!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you need to quote strings in a query, plus you had a bracket that wasn't supposed to be there ;)

And yes, it is best if you space your operators.
Post Reply