thereaper87 Posted August 5, 2011 Share Posted August 5, 2011 Hello there, I have an UPDATE sql state which is giving me some troubles Here is the update code $r_time = date("m/j/Y g:i A"); $u_time = date("U"); $news_id = (int)$news_id; $update_article_rate_up=mysql_query("UPDATE `articles` SET `up_rating`=(`up_rating`+1) AND `avg_rating`=(`avg_rating`+1) WHERE `id`=$news_id") or die("Error updating up rating"); $news_id is pulled from the URL. That's it. Nothing else. It is set as an integer. Here is the debugging verision: $r_time = date("m/j/Y g:i A"); $u_time = date("U"); $news_id = (int)$news_id; $update_article_rate_up=("UPDATE `articles` SET `up_rating`=(`up_rating`+1) AND `avg_rating`=(`avg_rating`+1) WHERE `id`=$news_id") or die("Error updating up rating"); echo $update_article_rate_up; This is what it says: UPDATE `articles` SET `up_rating`=(`up_rating`+1) AND `avg_rating`=(`avg_rating`+1) WHERE `id`=40 Which I think is right! What is going on here? Quote Link to comment https://forums.phpfreaks.com/topic/243874-need-help-on-debugging-sql-statement/ Share on other sites More sharing options...
Pikachu2000 Posted August 5, 2011 Share Posted August 5, 2011 It's close, but the syntax is of a bit. Comma, not AND . . . UPDATE table SET field1 = value1, field2 = value2, field3 = value3 WHERE field = condition Quote Link to comment https://forums.phpfreaks.com/topic/243874-need-help-on-debugging-sql-statement/#findComment-1252257 Share on other sites More sharing options...
thereaper87 Posted August 5, 2011 Author Share Posted August 5, 2011 Thank you! It now updates the row in phpmyadmin. But it does it twice! So instead have adding 1, it adds 2! Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/243874-need-help-on-debugging-sql-statement/#findComment-1252272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.