php run once and insert twice in mysql database php run once and insert twice in mysql database php php

php run once and insert twice in mysql database


I'm facing the same issue as you, the problem only occus when I use Opera or chrome.

For my case, I have an .htaccess to point every thing to the index file. Naturally the browser will request the script twice, once for the script it self, the other is for the favicon.

The fix:Try to edit the .htaccess to prevent redirection to the index file when the browser is requesting for favicon.ico


Do you see this

$result = $db->query($query);

And the next line:

if ($db->query($query) === TRUE) {

This means that you run your query twice. Remove one of the $db->query, e.g.:

$result = $db->query($query);if ($result === TRUE) {    /* do stuff */


Code is fine.

Try to change browser.If still not worked.

Restart serverStill not

Try to write in another file outside of project as single script.

It will work.

I tried your code its working on my system.