php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33705 Mysql inserts 2 rows, one of them blank
Submitted: 2005-07-14 20:56 UTC Modified: 2005-07-14 21:23 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: halehnb at hotmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.4.0 OS: Windows XP
Private report: No CVE-ID: None
 [2005-07-14 20:56 UTC] halehnb at hotmail dot com
Description:
------------
I am inserting into 2 tables, and each time in addition to inserting a row with the correct data, a phantom, blank row is inserted. This seems similar to bug #10599 "background attribute in the body tag causes a double insert", but I am not using the "background" tag, and I can't find my error. I am using "background-color" in CSS but I don't see how this could be a problem. What is also weird is that for the "sur_subcategory" table, the data is being inserted near the top of the database table, and not at the bottom like one would expect. Another anomoly: when I use Mozilla (1.4) it double inserts into both tables, but when I use IE (6.0), it only double inserts into one table (sur_category_subcategory). 



Reproduce code:
---------------
$step1 = '';

// sur_subcat table insert
$step1 = sprintf("INSERT INTO sur_subcategory (subcat_name) VALUES ('%s')",$subname);
$result1 = mysql_query($step1);

// get subcat_id to put into sur_cat_sub table
$step2 = sprintf("SELECT subcat_id FROM sur_subcategory WHERE subcat_name = '%s'", $subname);
$result = mysql_query($step2);
$subcat_id = mysql_result($result,0); 

// insert into sur_cat_sub table
$step3 = sprintf("INSERT INTO sur_category_subcategory (category_id,subcat_id,subcat_name) 
					VALUES ('%d','%d','%s')",$category_id,$subcat_id,$subname);
$result3 = mysql_query($step3);
?>
<br>
<?
echo ("<b>Your subcategory has been submitted</b>.");
mysql_close();
?>

Expected result:
----------------
What I want is for a SINGLE row with the subcat_name to be inserted into table sur_subcategory, and a SINGLE row with the category_id, subcat_id and subcat_name to be inserted into the  sur_category_subcategory table.

Actual result:
--------------
When I insert into sur_subcategory, a row with the correct information is created. However, another row with incorrect information is created too. The same happens when I try to insert into sur_category_subcategory. Example:

when $subname = "halehtest1", and the first mysql insert is done, the sur_subcategory table looks like:

-- 
-- Table structure for table `sur_subcategory`
-- 

CREATE TABLE `sur_subcategory` (
  `subcat_id` smallint(8) unsigned NOT NULL auto_increment,
  `subcat_name` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`subcat_id`)
) TYPE=MyISAM AUTO_INCREMENT=126 ;

-- 
-- Dumping data for table `sur_subcategory`
-- 

INSERT INTO `sur_subcategory` VALUES (124, 'halehtest1');
INSERT INTO `sur_subcategory` VALUES (125, '');



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-14 21:23 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 18:01:30 2024 UTC