php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35127 Update query after insert, select
Submitted: 2005-11-06 16:12 UTC Modified: 2005-11-06 17:07 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sketchdude at gmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.4.1 OS: WindowsXP, Linux
Private report: No CVE-ID: None
 [2005-11-06 16:12 UTC] sketchdude at gmail dot com
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-06 17:07 UTC] sketchdude at gmail dot com
My own bad variable. Sorry for wasting your time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC