PHP MYSQL script executed twice

RESOLVED INCOMPLETE

Status

()

Firefox
General
RESOLVED INCOMPLETE
9 years ago
7 years ago

People

(Reporter: Szaszem, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [CLOSEME 2011-1-1])

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2

If a PHP script contains INSERT INTO statement and this statement is run WHEN THE PAGE LOADS AT FIRST TIME, in the MYSQL database there will be two inserted lines instead of one. Second line often is empty, but sometimes contains  inserted data, could not figure out the reason yet. If the page is recalled by itself and the INSERT INTO statement is executed at recall, all is OK, one line is inserted only. When inserted randomly generated data into MYSQL I observed that the script is executed twice and the two inserted lines contains different random data. Tested against Internet Explorer 5, this bug does not exist there. In my special case MYSQL runs under Linux. 

Reproducible: Always

Steps to Reproduce:
1. In PHP MYSQL run INSERT INTO statement as the page loads.
2. Auto-recall page conditioned and run INSERT INTO statement - the bug disappears.


Actual Results:  
two lines inserted into MYSQL database instead of one, second often empty.

Expected Results:  
one line inserted into MYSQL Database

Example to bad working script:
<?php

//open
mysql_query(INSERT INTO database (a, b...) VALUES ($a, $b...) 
//close

// other code

?>


Example to good working script:
<?php
if ($_REQUEST['redisplay']=="2")
{
//open
mysql_query(INSERT INTO database (a, b...) VALUES ($a, $b...) )
//close
}

else
{
// other scripts
......
<form action='this page itself.php'>
<input type='hidden' name='redisplay' value='2'>
.....
</form>
}
?>

Comment 1

9 years ago
You need to give more information, like the URL of a testpage, otherwise we can't figure out why the page is loaded twice. The PHP code does no good here.

Also note that it is an extremely bad idea to write this kind of the code - the PHP code code should protect itself against a double insert, because that would might be a very common occurrence. There could be indeed a problem with the browser, but the user can also accidentally press a link twice (browsers tries to detect the double click, but if you do it slow enough, it's treated as 2 single clicks), or press refresh. Or the page itself can refresh itself. Or there might be an issue with caching (if it's cached, the insert will not happen).
Reporter, are you still seeing this issue with Firefox 3.6.12 or later in safe mode? If not, please close. These links can help you in your testing.
http://support.mozilla.com/kb/Safe+Mode
http://support.mozilla.com/kb/Managing+profiles
Also, please consider using the most recent Firefox 4 beta build, your bug may be resolved there.
Whiteboard: [CLOSEME 2011-1-1]
No reply, INCOMPLETE. Please retest with Firefox 3.6.13 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.