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
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

Link to comment
Share on other sites

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!!!???

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.