开发者

Why does my MySql query run twice?

I got a page which is URLRewrited by the .htaccess which runs a MySQL query twice eventhough I place it once, no loops no nothing.

.htaccess

RewriteRule ^go/([a-zA-Z0-9-_]+)$ /go.php?id=$1&%{QUERY_STRING}
RewriteRule ^go/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)$ /$2.php?id=$1%{QUERY_STRING}

go.php

<?php
$update = mysql_query('UPDATE table SET page_views=page_views+1 WHERE id =123');
?>
开发者_开发百科

Every time i refresh the page it adds 2 page views to the database, why is this?


Is whatever generates the RSS feed calling that function too?

I had a similar problem with Wordpress plugin dev before. Firefox does some sort of prefetch of the RSS, that causes 2 requests somehow..

Edit: The above didn't work. Do you have xdebug enabled? Use xdebug_get_function_stack to see what paths are followed to get to your query.


It's a Browser Problem ;) Try with IE it will not Run Twice.

If you use Firefox Disable All Plugins.


The issue is with your HTML submitting the script twice. example below worked for me

if($POST){
  $update = mysql_query('UPDATE table SET page_views=page_views+1 WHERE id =123');
 }

OR you can use GET to validate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜