Okay, so basically I have a problem with my image board system i'm trying to write... I need some way of naming the image and LINKING the image to the post.
I was thinking that I could submit the post to the SQL database (the topic/text stuff...) and then get the ID number (from auto-increment ID column in SQL table) and name the image that. That way the post and image are linked by ID number.
My question is, how do I get the number of the last query submitted? I realize I could look at the last thing in the database, but if someone ELSE were to submit a post from another browser at that fraction of a second in-between the submit post text and retrieve ID number of last entry queries... it would get the wrong number.
Is there something like "return ID" or something simple I should know about SQL queries that I could use in this circumstance?
Help is much appreciated. ^_^.
Get SQL ID of last SQL query?
Moderator: General Moderators
-
pyromaster114
- Forum Newbie
- Posts: 19
- Joined: Fri Mar 14, 2008 8:12 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Get SQL ID of last SQL query?
mysql_insert_id() will give you the id assigned of an insert
-
pyromaster114
- Forum Newbie
- Posts: 19
- Joined: Fri Mar 14, 2008 8:12 pm
Re: Get SQL ID of last SQL query?
So I can like have the mysql_insertid(mysql_query("INSERT INTO posts....etc"));
?
Thank you ^_^ I shall try it ^_^.
?
Thank you ^_^ I shall try it ^_^.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Get SQL ID of last SQL query?
read the documentation on mysql_insert_id() 