query problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jrucifer
Forum Commoner
Posts: 32
Joined: Fri May 13, 2005 2:36 pm
Location: phoenix

query problem

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
Post Reply