From: halehnb at hotmail dot com
Operating system: Windows XP
PHP version: 4.4.0
PHP Bug Type: MySQL related
Bug description: Mysql inserts 2 rows, one of them blank
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, '');
--
Edit bug report at http://bugs.php.net/?id=33705&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33705&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=33705&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=33705&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33705&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33705&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33705&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33705&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33705&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33705&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33705&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=33705&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=33705&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33705&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33705&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33705&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33705&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33705&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33705&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33705&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33705&r=mysqlcfg