Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Query: Incrementing by two instead of 1
    text
    copied!<p>I am trying to update a field in a table by increasing its integer value by 1. Here is what I am using:</p> <pre><code>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; } </code></pre> <p>However, I find its incrementing by 2 each time rather than 1? What am I doing wrong?</p> <p>Thanks</p> <h2>Update</h2> <p>From the answers the SQL is correct. Do you think this may be affected 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.</p> <h2>Update 2</h2> <p>Using the debug function. I get this output:</p> <pre><code>array(4) { ["file"]=&gt; string(35) "/home/magic/public_html/dbUpdate.php" ["line"]=&gt; int(16) ["function"]=&gt; string(15) "myDebugFunction" ["args"]=&gt; array(0) { } } array(4) { ["file"]=&gt; string(31) "/home/magic/public_html/view.php" ["line"]=&gt; int(10) ["function"]=&gt; string(11) "updateViews" ["args"]=&gt; array(1) { [0]=&gt; &amp;string(5) "7jjdd" } } </code></pre> <p>It looks as if the script is being called once but it is still getting updated twice??? HELP! :( </p> <p>Also from the Log file, it looks as if the scripts are being called three times??</p> <pre><code>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 </code></pre> <h2>UPDATE 3</h2> <p>Here is the contents of my htaccess file which may be causing a problem.</p> <pre><code># 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} ^([^&amp;]*&amp;)*t=([^&amp;]+)&amp;?.*$ RewriteRule ^view\.php$ /%2? [L,R=301] # /h5k6 internally to /view.php?t=h5k6 RewriteRule ^([0-9a-z]+)$ view.php?t=$1 [L] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload