I am using this code so I can update a record in database:
$query = mysql_query("UPDATE article
SET com_count = ". $comments_count
WHERE article_id = .$art_id ");
My question is: How can I use variables in a MySQL UPDATE statement.
$query = mysql_query("UPDATE article set com_count = $comments_count WHERE article_id = $art_id");
You was messing up the quotes and concats.
You can use inline vars like the previous example or concat them like:
$query = mysql_query("UPDATE article set com_count = " . $comments_count . " WHERE article_id = " . $art_id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With