php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33544 mysql_query() duplicate entries
Submitted: 2005-07-02 05:08 UTC Modified: 2005-07-10 01:00 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: mmokhtar at gmail dot com Assigned:
Status: No Feedback Package: MySQL related
PHP Version: 4.3.10 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
49 - 42 = ?
Subscribe to this entry?

 
 [2005-07-02 05:08 UTC] mmokhtar at gmail dot com
Description:
------------
I use mysql_query() to execute an insert statement into MySql db (ver 4.0.21). Sometimes the query executes correctly inserting a unique record into the table. Other times it inserts two duplicate records. 

I've tested this several times, and get this random result...however more duplicate entries than single entry during my tests. 

Reproduce code:
---------------
$host = 'localhost'; 
$user = 'user'; 
$pass = 'pass'; 
$db = 'db'; 

//$selected_prj = $_GET['prjID'];
$formsubmit = 0;
$formsubmit = $_POST['formsubmit'];

$conn = mysql_connect($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ($db, $conn) or die("Couldn't access database $db on MySQL server $host: ".mysql_error()); 

if ($formsubmit == '1'){
	
	$queryInsert = "Insert into prjs (prjOwnerID, prjAssignedTo, prjTypeID, prjName, prjDescription, prjComments, prjStatusID, startDate, endDate, CreateDate, LastUpdate) Values (" . $_POST['ClientID'] . ", " . $_POST['AssignedToID'] . ", " . $_POST['prjTypeID'] . ", '" . $_POST['prjName'] . "', '" . $_POST['prjDescription'] . "', '" . $_POST['prjComments'] . "', " . $_POST['prjStatusID'] . ",'" . $prj_StartDate . "', '" . $prj_EndDate . "', now(), now())";
	
	if(!($Result = mysql_query($queryInsert))){
		// get error and error number
		$errno = mysql_errno($conn);
		$error = mysql_errno($conn);
		
		print("Error $errno: $error<br>\n");
	}
	else{
		print("<script language=\"javascript\"> ");
		print("window.opener.location='./myaccount.php'; ");
		print("self.close();");
		print("</script>");
	}
}

Expected result:
----------------
Record is inserted, opening window gets refreshed and current window is closed.

Actual result:
--------------
two Records are inserted, opening window gets refreshed and current window is closed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 16:01:27 2024 UTC