LAST_INSERT_ID()
Moderator: General Moderators
- chopper_pc
- Forum Newbie
- Posts: 15
- Joined: Fri May 30, 2008 10:55 pm
LAST_INSERT_ID()
I have a html form that passes information to a php script that builds a record in a table. I am trying to find out how to be able to get the id (primary key) of the new record. I have googled and the best I have come with is using LAST_INSERT_ID(). From what I understand that grabs the id of the last record put in any table in the database. That will not work. Really all I want to do is display the new record in a special formatted page I have built already. Any Ideas of functions that might do this or places to look?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: LAST_INSERT_ID()
mysql_insert_id() will give you the last id generated from auto increment in your connection.
- chopper_pc
- Forum Newbie
- Posts: 15
- Joined: Fri May 30, 2008 10:55 pm
Re: LAST_INSERT_ID()
Thanks,
knowing that I now have the output url http://localhost/mypage.php?postid=81, whats the proper usage on the mypage.php to use this?
mysql_query("select * from BOL WHERE id=????
knowing that I now have the output url http://localhost/mypage.php?postid=81, whats the proper usage on the mypage.php to use this?
mysql_query("select * from BOL WHERE id=????
- chopper_pc
- Forum Newbie
- Posts: 15
- Joined: Fri May 30, 2008 10:55 pm
Re: LAST_INSERT_ID()
Solved.......
$postid = $_GET['postid'];
mysql_query("select * from BOL WHERE id=$postid........
Sorry, I really need to sleep more often
$postid = $_GET['postid'];
mysql_query("select * from BOL WHERE id=$postid........
Sorry, I really need to sleep more often
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
Re: LAST_INSERT_ID()
Whatch out for sql injection, you need to escape the parameters:
or at least make sure it's a integer (if that's what it is)
Code: Select all
$postid = mysql_real_escape_string($_GET['postid']);