tags:

views:

324

answers:

4

I have the following code:

$sql = "INSERT INTO table VALUES ('', ...)";
$result = mysql_query($sql, $link) or die(mysql_error());
$id = mysql_insert_id($result) or die('oops'); //mysql_error() instead of oops produces the same result
echo $id . "\nDone";

The table that this insert occurs on has an auto-incroment field however all that this outputs is:

Done

Am I doing something wrong?

+8  A: 

You do not need to pass $result to mysql_insert_id you should pass $link variable.

Irmantas
+1  A: 

do mysql_insert_id($link) or mysql_insert_id() instead of mysql_insert_id($result) since mysql_insert_id parameter is [resource $link_identifier]

aivarsak
+2  A: 

The mysql_insert_id() function expects the first parameter to be a connection resource.

Gumbo
+1  A: 

You don't need to pass it anything, and if you do you should be passing the connection var

Andrew G. Johnson