0

Not sure what is causing this, but I have two ints, like and dislike. They're updated by the mysql query:

    if ($like == "like"){
    mysql_query("UPDATE updates set like = like + 1 WHERE id='$id'");
    echo $like;
} else if ($like == "dislike") {
    mysql_query("UPDATE updates set dislike = dislike + 1 WHERE id = '$id'");
    echo $like;
}   

The echo comes out, but, the actual query does not update the value. I'm baffled as to why this happens. Any reason as to why this happens? Thanks, Chris

CCates
  • 1,225
  • 2
  • 9
  • 13
  • You are not doing any error checking in your queries so it's no wonder they break silently. See e.g. this reference question for how to do a proper mySQL query: http://stackoverflow.com/questions/6198104 – Pekka Mar 07 '12 at 17:17
  • I would recommend that you assign the query to a variable and echo that out as your debug. This will give you insight as to what SQL you are running. – James C Mar 07 '12 at 17:21

2 Answers2

1

You have not shown us where you set $id which is critical. I am assuming it's some form of GET or POST, but until I see I am unsure.

Thomas
  • 1,401
  • 8
  • 12
  • $id = $_GET['associd']; This is set from an AJAX request. When I echo ID, it appears correctly as well. – CCates Mar 07 '12 at 17:16
1

Maybe because like is a reserved word in most SQL dialects. You may need to put the like in double quotes.

Refer to this list of reserved words for MySQL: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

dcp
  • 54,410
  • 22
  • 144
  • 164