By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,050 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,050 IT Pros & Developers. It's quick & easy.

PHP another mysql_insert_id() not working

P: 88
I have one database connection
I am using an insert statement
The insert statement inserts successfully
Right after the insert I want the ID of the newest row
My database table has a unique ID and set to auto inc
mysql workbench version is 5.2.34
Expand|Select|Wrap|Line Numbers
  1. $save = mysqli_query($connection,"insert into table (message, title, newdate) values ('$Message', '$itle', CURDATE())");
  2.     $newid =  mysql_insert_id($connection);echo('val is '. $newid);
The value of $newid is always empty or 0
Please help!
Feb 11 '12 #1
Share this Question
Share on Google+
2 Replies

P: 23
why don you try some thing of this nature it works perfectly for me

Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT into `table` (`message`,`title`,`newdate`)
  2.     VALUES
  3. ('$message','$title', CURDATE())";
  5. mysql_query($query,$connection) or die("Insertion Failed:" . mysql_error());
  6. $newest_id = mysql_insert_id($connection);
and dont forget to escape your query data using mysql_real_escape_string()

If you find any error let me know
Feb 11 '12 #2

Expert Mod 5K+
P: 8,639
in case you didn’t notice:
Expand|Select|Wrap|Line Numbers
  1.  $save = mysqli_query($connection,"insert into table (message, title, newdate) values ('$Message', '$itle', CURDATE())");
  2. // -----------^ 
  3. $newid = mysql_insert_id($connection);echo('val is '. $newid);
  4. // -----------^ 
Feb 12 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.