$dml = "insert into ... ";
mysql_query($dml,$con);
$Id = isset($row) ? $row['id'] : mysql_insert_id($con);
I saw the record is created,but just can't retrieve the Id.
What's wrong?
EDIT
fixed,it's caused by $row.
$dml = "insert into ... ";
mysql_query($dml,$con);
$Id = isset($row) ? $row['id'] : mysql_insert_id($con);
I saw the record is created,but just can't retrieve the Id.
What's wrong?
EDIT
fixed,it's caused by $row.
Can you use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query instead?
From the PHP manual (http://php.net/manual/en/function.mysql-insert-id.php):
Return Values
The ID generated for an
AUTO_INCREMENT
column by the previous INSERT query on success, 0 if the previous query does not generate anAUTO_INCREMENT
value, or FALSE if no MySQL connection was established.
So, while this may seem silly, ensure that the table you are inserting your data into contains a column with the AUTO_INCREMENT
property set.
Hi,
Are you sure you have an auto_increment on that "id", in the table you just inserted some data ?
The manual of mysql_insert_id
states that :
Return Values
The ID generated for anAUTO_INCREMENT
column by the previousINSERT
query on success, 0 if the previous query does not generate anAUTO_INCREMENT
value, orFALSE
if no MySQL connection was established.
Maybe this explains the problem ?
If not, can you provide us with more informations ? Like the structure of the table, and/or a full insert query ?
$row must have been be set so its never evaluating the last_insert_id() call