Forum Moderators: coopster

Message Too Old, No Replies

Using AND in MySQL UPDATE command?

         

Dreap

7:29 pm on Apr 13, 2010 (gmt 0)

10+ Year Member



$user_id = "55"
$updated_period = "5000"
$user_color = "blue"

mysql_query("UPDATE clients_table SET period = '$updated_period' WHERE client_id = '$user_id'");



I need to get somehow to make it update table where user id is 55 and color is blue. *so it wouldn't update other blue ones nor other client ids.

Can I simply use following?

mysql_query("UPDATE clients_table SET period = '$updated_period' WHERE client_id = '$user_id' AND user_color = '$user_color'");

Readie

7:32 pm on Apr 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup.

If you are going to allow users any control over what these variables are, I strongly suggest you concatonate them in, and run them though strip_tags() and mysql_real_escape_string()

Dreap

7:41 pm on Apr 13, 2010 (gmt 0)

10+ Year Member



Yeah, I did that with your previous example already. Just tried to simplify the question.

Thanks once again :)