Page 1 of 1

query problem

Posted: Sat Jun 18, 2005 4:22 pm
by jrucifer
can someone please tell me whats wrong with this query?

Code: Select all

$sql = &quote; UPDATE $user WHERE id = $up_id&quote;;
$sql .= &quote; (subject, body) VALUES &quote;;
$sql .= &quote; ('$subject', '$body') &quote;;

$result = mysql_query($sql);
i get the error:

Code: Select all

Database ERROR: UPDATE price WHERE id = 94 (subject, body) VALUES ('gg', 'g') 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 id = 94 (subject, body) VALUES ('gg', 'g')' at line 1
i'm guessing i'm not using the update function right because when I use this query to insert data it works:

Code: Select all

$sql = " INSERT INTO $user ";
$sql .= " (subject, body, date) VALUES ";
$sql .= " ('$subject', '$body', NOW()) ";
$result = mysql_query($sql, $cid);
thank you

Posted: Sat Jun 18, 2005 4:25 pm
by hawleyjr
http://dev.mysql.com/doc/mysql/en/update.html

Code: Select all

UPDATE їLOW_PRIORITY] їIGNORE] tbl_name
    SET col_name1=expr1 ї, col_name2=expr2 ...]
    їWHERE where_definition]
    їORDER BY ...]
    їLIMIT row_count]

Posted: Sat Jun 18, 2005 4:26 pm
by onion2k
Update statements have a completely different syntax to inserts. Basically you want:

UPDATE table SET field='value', field='value, field='value' WHERE field='value';

Read the Mysql docs.