Jump to content

Archived

This topic is now archived and is closed to further replies.

dagnasty

Posting to MySQL, then getting the row number?

Recommended Posts

I'm making a poll system, but am confused by one thing.

Consider:
2 seperate polls can have the same poll name in the mysql database.

If after a user creates a poll, how do I go about getting the poll mysql id (auto incrementing) after the poll is created through a form. When post a new row the a mysql database, is there a way to find out it's location if it has auto incrementing id field?

For instance, if a user creates the poll and is taken to a "thanks for posting your poll. Here is a link to it"

Share this post


Link to post
Share on other sites
If you have an auto_increment field in the table and you want to know what the last value was set to, it's just mysql_insert_id(). You must have one and only one auto_increment column.

Share this post


Link to post
Share on other sites
What if multiple users are submitting simultaneously (not likely, but possible) would this be accurate?

Share this post


Link to post
Share on other sites
Ahh i see it's put right after the query. I was thinking it called from the next page.

Share this post


Link to post
Share on other sites
[quote author=dagnasty link=topic=102476.msg406700#msg406700 date=1154374597]
Ahh i see it's put right after the query. I was thinking it called from the next page.
[/quote]
Yup. if you call it on the next page it might be another one. as long as you don't close the connection or perform another insert on the same page it will be the last id from the current connection.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.