I can't seem to find this. Maybe I'm asking the wrong question. My first field in my db is an id with INT set to auto increment. When I create a new entry I want to grab the id that was created, but I don't know how.
$query = mysqli_query($myConnection, "INSERT INTO books (title, author, description)
VALUES('$title','$author','$description')")
or die (mysqli_error($myConnection));
echo 'Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a><br /><br />';
//HERE I WOULD ALSO LIKE TO ECHO THE ID THAT WAS CREATE WITH AUTO INCREMENT
echo $title . "<br />" . $author . "<br /> . $description;
Try this:
echo "The last id was: " . msqli_last_insert_id();
Use this function: mysqli_insert_id()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With