|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2005-11-06 17:07 UTC] sketchdude at gmail dot com
 | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 15:00:01 2025 UTC | 
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.