Scripts and functions that I have written or found useful

PHP Get last inserted ID from mysql

August 18th, 2007 Posted in MYSQL, PHP

$id = mysql_insert_id();

Each person on the website has a different session so if you use the above, it will automatically know which row was inserted last with this session. You do not need to worry about 2 people being on the site at the same time and creating 2 different rows.

  1. One Response to “PHP Get last inserted ID from mysql”

  2. By Mark on Feb 13, 2008

    Worked great for me, thanks!
    Just put this line of code directly after your insert query and you’re good to go.

Post a Comment