Jump to content

UPDATE help - whats the correct way?


herghost

Recommended Posts

Hi all,

 

Whats the correct way of putting this statement?

$query ="UPDATE customers SET
(title, forename, surname, company, nameno, fline, sline, city, state, zip, country, tax, email, phone, fax, username, password, newsletter)
VALUES
('$title', '$forename', '$surname', '$company', '$nameno', '$fline', '$sline', '$city', '$state', '$zip', '$country', '$tax', '$email', '$phone', '$fax', '$username', '$password', '$newsletter')

WHERE id = '$id';"

 

Link to comment
https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/
Share on other sites

Sorry,

 

yes this does not work, I am getting

Error: 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 '(title, forename, surname, company, nameno, fline, sline, city, state, zip, coun' at line 2

 

I'm thinking it is likely you are using a mysql reserved keyword in one of you column names. Check the mysql manual to be sure. If you are, just change them and try again.

 

This is one THE most annoying errors. Had it a once and spent days trying to resolve it because of that absolutely useless error feedback.

 

Here's a link:

 

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

 

--- and this is my lack of knowledge coming out - but can you even use an update query in that format?

 

My understanding was it had to be structured like this:

 

$result = mysql_query("UPDATE example SET age='22',field2='val2',field3='val3' WHERE age='21'")

 

That's not the syntax for an UPDATE query -

UPDATE [LOW_PRIORITY] [iGNORE] table_reference

    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...

    [WHERE where_condition]

    [ORDER BY ...]

    [LIMIT row_count]

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.