I'm trying to grab a value from the database and then add one to it, but for some reason it add's two. I have the following code:
$sqlviews = "SELECT views FROM forum_messages where messageid='$messageid'";
$resultviews = mysql_query($sqlviews) or die(mysql_error());
$row = mysql_fetch_array($resultviews);
$views = $row['views'];
echo "The value from the db is: $views<br>";
$views = $views + 1;
echo "The update value from the db is: $views<br>";
$sqlupdate = "Update forum_messages set views='$views' where messageid='$messageid'";
echo $sqlupdate;
$resultupdate = mysql_query($sqlupdate);
When I echo The value from the db is: $views it already adds the 1 already from the database and I'm not sure why. Then when I add 1 to it that makes it two, but if I do this:
$sqlviews = "SELECT views FROM forum_messages where messageid='$messageid'";
$resultviews = mysql_query($sqlviews) or die(mysql_error());
$row = mysql_fetch_array($resultviews);
$views = $row['views'];
echo "The value from the db is: $views<br>";
//$views = $views + 1;
//echo "The update value from the db is: $views<br>";
$sqlupdate = "Update forum_messages set views='$views' where messageid='$messageid'";
echo $sqlupdate;
$resultupdate = mysql_query($sqlupdate);
When I do that it doesn't add anything. The code is only getting executed once so I can't figure out what the problem is. Any help is greatly appreciated.