# mysql\_insert\_id() doesn't work

**URL:** <https://forum.kirupa.com/t/mysql-insert-id-doesnt-work/296352>\
**Category:** programming\
**Created:** [September 14, 2009, 3:58am UTC](https://forum.kirupa.com/t/mysql-insert-id-doesnt-work/296352 "2009-09-14T03:58:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyg3r](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tyg3r/32/1341_2.png) [@Tyg3r](https://forum.kirupa.com/u/Tyg3r)\
**Post date:** [September 14, 2009, 3:58am UTC](https://forum.kirupa.com/t/mysql-insert-id-doesnt-work/296352/1 "2009-09-14T03:58:27Z")

</div>

Hi,

I’ve attempted about 20 different variations of what is effectively the same job; and I just can’t get it to work. 💢

I’ve inserted some information into the mysql database. Now all I want is to return the ID. The ID is auto\_increment and has Zerofill. I’m not sure if this is effecting my attempt, but all I get is a single 0. What am I doing wrong?

```auto
$SQL = "INSERT INTO db_table (name, email) VALUES ('$name', '$email')";
echo "The last inserted ID was : " . mysql_insert_id();

```

Thanks, Mark.
