I am trying to update a column for a certain user with PHP/MySQL. What is the proper way for me to set that equal to a variable?
$style is equal to a value that is from a form (post).
When setting 'style' equal to a string value that is also in single quotes, I do not get an error. I only get an error when setting 'style' equal to a variable.
$query = "UPDATE `users`
SET `style` = $style
WHERE `id` = $userid;";
Thank you very much.
You still have to put quotes around the variable as they are needed to tell MySQL that is a string. Remember, the variables are interpolated before the query is sent to the MySQL server. So $style
is replaced by it's value before the query is run.
$query = "UPDATE `users`
SET `style` = '$style'
WHERE `id` = $userid;";