MySQL Forums
Forum List  »  PHP

Re: mysql_insert_id(); returnig 0 Record is added and the field is auto_increment?!!
Posted by: Rick James
Date: February 15, 2014 12:55PM

> $lastid ="SELECT LAST_INSERT_ID()"; // doesnt WORK

That gives you a string. You need to use mysql_query()

> $con=mysqli_connect(...);
> $sql="INSERT ...";
> $result = mysql_query($sql,$con);
> echo "ID of last inserted record is: " . mysql_insert_id();

Don't mix mysqli_* and mysql_* functions; they don't talk to each other. Use _only_ mysqli_*.

You failed to check for $result being FALSE, indicating some kind of error in the INSERT.

$_POST[...] could contain an apostrophe, thereby causing a syntax error. Escape data from <form>s.

Options: ReplyQuote


Subject
Written By
Posted
Re: mysql_insert_id(); returnig 0 Record is added and the field is auto_increment?!!
February 15, 2014 12:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.