Jump to content

Problem in Returning the last insert id?


radiations3

Recommended Posts

I am using the following code to return the last insert id from the table employee kindly let me know what is wrong with the following code:

<?php

$temp_array = mysql_query("select last_insert_id() from employee");

 

//now you can display it, to test it

echo $temp_array;

?>

Link to comment
https://forums.phpfreaks.com/topic/244127-problem-in-returning-the-last-insert-id/
Share on other sites

On the following code

 

<?php 
$temp_array = mysql_fetch_array(mysql_query("select last_insert_id() from employee")); 
$my_last_id = $temp_array['last_insert_id()'];
//now you can display it, to test it 
echo $my_last_id ; 
?>

 

following error is occuring:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\DBMS\untitled.php on line 10

PHP has a built in function for that: mysql_insert_id. If you need to use the MySQL LAST_INSERT_ID() function directly, read the manual entry for it. Your syntax is off.

 

How to use  mysql_insert_id() to retrieve the last id from the table employee

 

KINDLY HELP!!!???

OK, since it's kind of vague.  The id it returns is not table specific.  It is for the last successful insert query.  Not foolproof, but if you need it for a specific table you might do:

 

SELECT MAX(id) FROM employee

OK, since it's kind of vague.  The id it returns is not table specific.  It is for the last successful insert query.  Not foolproof, but if you need it for a specific table you might do:

 

SELECT MAX(id) FROM employee

 

Besides above mentioned method....Can anyone kindly guide me how can i return my last id to use  mysql_insert_id() from the table employee

 

KINDLY HELP!!!???

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.