Jump to content

Number is incrementing by 2 instead of 1!!!?!?!


lip9000

Recommended Posts

I have a script that updates the 'views' field in a database, as I want it to increase by 1 when a person loads the page.

 

The script goes as follows, and is at the very bottom of the page:

 

$updateSQL = sprintf("UPDATE tblvideos SET views=views + 1 WHERE videoID=%s",
                       GetSQLValueString($video, "int"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());

 

The script works, however when I refresh the page, the views increases by 2 instead of 1. I have tried changing "views + 1" to "views + 0" but then the views just stays the same and doesn't change, as it should.

 

I have this exact same script on another site, and the views do indeed increase by 1 instead of 2.

 

I have also tried this script by getting the current value of "views" in a variable, then increasing that varible by 1, and inserting that value into the query, but get the same result, an increase by 2 instead of 1.

 

$tempview = $row_rsVideosWatch['views'];
$nextview = $tempview + 1;

$updateSQL = sprintf("UPDATE tblvideos SET views=$nextview WHERE videoID=%s",
                       GetSQLValueString($video, "int"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());

 

Any suggestions??? This is really weird and is causing me to pull my hair out!!!

Link to comment
https://forums.phpfreaks.com/topic/98276-number-is-incrementing-by-2-instead-of-1/
Share on other sites

$updateSQL = sprintf("UPDATE tblvideos SET views= (views + 1) WHERE videoID=%s",

 

Nope, it's still incrementing by 2. Even if I do + 0 instead of plus 1, logically you'd think it would only increase by 1, if the current code is already increasing it by 2. But instead of doesn't add anything.

 

And no there is only 1 mysql_query($updateSQL, $conn)

please echo $updateSQL

 

what the query its printing

 

copy that query and run it in mysql without any php code (using phpmyadmin or any other tools)

 

it echoed out as

 

UPDATE tblvideos SET views=(views + 1) WHERE videoID=14

 

I ran it in phpMyAdmin, and sure enough the correct record increased by 1. So it works in there, but not in the document where its being executed, so perhaps theres another bit of code somewhere thats stuffing something up??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.