Reputation: 618
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?
Upvotes: 0
Views: 1871
Reputation: 524
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.
Upvotes: 0
Reputation: 31
It's a Browser Problem ;) Try with IE it will not Run Twice.
If you use Firefox Disable All Plugins.
Upvotes: 2
Reputation: 21249
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.
Upvotes: 2