#35127 [NEW]: Update query after insert, select
| From: | sketchdude at gmail dot com | Date: | Sun, 06 Nov 2005 15:12:09 +0000 |
| Subject: | #35127 [NEW]: Update query after insert, select | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-87690@lists.php.net to get a copy of this message | ||
From: sketchdude at gmail dot com
Operating system: WindowsXP, Linux
PHP version: 4.4.1
PHP Bug Type: MySQL related
Bug description: Update query after insert, select
Description:
------------
The cat_id fields fails to update after an insert and select query. (see
sql example below)
/*
use thisexample;
CREATE TABLE example (
example_id int unsigned not null auto_increment,
cat_id int unsigned not null,
name varchar(35) not null,
total tinyint unsigned not null,
PRIMARY KEY (example_id)
);
INSERT INTO example VALUES (1,1,'One',1);
INSERT INTO example VALUES (2,2,'Two',0);
INSERT INTO example VALUES (3,3,'Three',0);
INSERT INTO example VALUES (4,4,'Four',0);
*/
Reproduce code:
---------------
$name = 'Five';
$query = "INSERT INTO example (example_id, cat_id, name, total) VALUES
('', 0, '$name', 0)";
if (!$result = mysql_query($query)) {
print "Insert query failed ($query) : " . mysql_error();
exit;
}
$query = "SELECT example_id AS new_id FROM example WHERE name ='$name'";
if (!$result = mysql_query($query)) {
print "Select query failed ($query) : " . mysql_error();exit;
}
else {
$new_id = mysql_fetch_row($result);
$query = "UPDATE example SET cat_id = '$new_id[0]' WHERE example_id =
'$name'";
if (!$result = mysql_query($query)) {
print "Update query failed ($query) : " . mysql_error(); exit;
}
else {
print "Script ran successfully! New cat_id = " . $new_id[0];
}
}
Expected result:
----------------
The problem is the third query: cat_id field should be updated to 5, or
else the script should die and print out the query.
Actual result:
--------------
The script executes successfully, but the cat_id field remains at 0.
--
Edit bug report at http://bugs.php.net/?id=35127&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35127&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35127&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35127&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=35127&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35127&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35127&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35127&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35127&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35127&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35127&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35127&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35127&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35127&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35127&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35127&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35127&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35127&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35127&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35127&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35127&r=mysqlcfg