dagnasty Posted July 31, 2006 Share Posted July 31, 2006 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" Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/ Share on other sites More sharing options...
ryanlwh Posted July 31, 2006 Share Posted July 31, 2006 mysql_insert_id() Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66566 Share on other sites More sharing options...
king arthur Posted July 31, 2006 Share Posted July 31, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66567 Share on other sites More sharing options...
dagnasty Posted July 31, 2006 Author Share Posted July 31, 2006 What if multiple users are submitting simultaneously (not likely, but possible) would this be accurate? Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66568 Share on other sites More sharing options...
ryanlwh Posted July 31, 2006 Share Posted July 31, 2006 yes, it will be accurate. Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66571 Share on other sites More sharing options...
dagnasty Posted July 31, 2006 Author Share Posted July 31, 2006 Ahh i see it's put right after the query. I was thinking it called from the next page. Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66574 Share on other sites More sharing options...
dagnasty Posted July 31, 2006 Author Share Posted July 31, 2006 Thanks guys you're the best! Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66575 Share on other sites More sharing options...
ryanlwh Posted July 31, 2006 Share Posted July 31, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/16135-posting-to-mysql-then-getting-the-row-number/#findComment-66577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.