Hello all,
I am trying to update a field in a table by increasing its integer value by 1. Here is what I am using:
function updateViews($id){
$sql = "UPDATE tweets SET tweet_views = tweet_views + 1 WHERE tweet_key = '$id'";
$result = mysql_query($sql) or die("DB Error : ". mysql_error());
return $result;
}
However, I find its incrementing by 2 each time rather than 1? What am I doing wrong?
Thanks
Update
From the Answers the SQL is correct. Do you think this may be effected by the rewrite engine??? I ask because I am 100% sure this doesn't run twice or that I don't make the call since there are two scripts. One that calls the function and one that holds the function! This is confusing.
Update 2
Using the debug function. I get this output:
array(4) {
["file"]=>
string(35) "/home/magic/public_html/dbUpdate.php"
["line"]=>
int(16)
["function"]=>
string(15) "myDebugFunction"
["args"]=>
array(0) {
}
}
array(4) {
["file"]=>
string(31) "/home/magic/public_html/view.php"
["line"]=>
int(10)
["function"]=>
string(11) "updateViews"
["args"]=>
array(1) {
[0]=>
&string(5) "7jjdd"
}
}
It looks as if the script is being called once but it is still getting updated twice??? HELP! :(
ALso from the Log file, it looks as if the scripts are being called three times??
13:16:28 id:4a6c9d7cf38016.29304000
_SERVER[REQUEST_URI]=/lucic
_SERVER[REDIRECT_URL]=/lucic
/home/magic/public_html/dbUpdate.php@16 :myDebugFunction
/home/magic/public_html/view.php@10 :updateViews
13:16:30 id:4a6c9d7eaf93e3.88114161
_SERVER[REQUEST_URI]=/lucic
_SERVER[REDIRECT_URL]=/lucic
/home/magic/public_html/dbUpdate.php@16 :myDebugFunction
/home/magic/public_html/view.php@10 :updateViews
13:16:31 id:4a6c9d7f846557.12618673
_SERVER[REQUEST_URI]=/lucic
_SERVER[REDIRECT_URL]=/lucic
/home/magic/public_html/dbUpdate.php@16 :myDebugFunction
/home/magic/public_html/view.php@10 :updateViews
UPDATE 3
Here is the contents of my htaccess file which may be causing a problem.
# REWRITE DEFAULTS
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
# /view.php?t=h5k6 externally to /h5k6
RewriteCond %{THE_REQUEST} ^GET\ /view\.php
RewriteCond %{QUERY_STRING} ^([^&]*&)*t=([^&]+)&?.*$
RewriteRule ^view\.php$ /%2? [L,R=301]
# /h5k6 internally to /view.php?t=h5k6
RewriteRule ^([0-9a-z]+)$ view.php?t=$1 [L]