frankerpulten Posted March 15, 2009 Share Posted March 15, 2009 Hi, I'm very new to php and mysql, sorry if I'm unclear on anything. I've created a form where people enter in information, and this then creates an entry in a table in a DB. After that they are transferred to another page with more questions that need to be put in the same row. After that questionnaire is submitted, it loads up a flash application that needs to send information to the table still. All of this needs to go within the same line for each user. I was thinking that I need to request the ID from the mysql table when the information is first inserted and then store the ID in a session so that the other pages know which row to update to. I am not exactly sure how to use sessions, or how to recall the unique ID created when first inserting data. any help would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/149455-sessions-and-mysql/ Share on other sites More sharing options...
shlumph Posted March 15, 2009 Share Posted March 15, 2009 When using sessions, always have this at the top of your page: <?php //Tell the server you're using sessions session_start(); Use mysql_insert_id() to retrieve the last insert id: <?php $sql = "INSERT bla bla bla"; mysql_query($sql) or die(mysql_error()); $_SESSION['id'] = mysql_insert_id();//this variable gets carried to whatever page has session_start() at the top echo $_SESSION['id']; Link to comment https://forums.phpfreaks.com/topic/149455-sessions-and-mysql/#findComment-785245 Share on other sites More sharing options...
frankerpulten Posted March 17, 2009 Author Share Posted March 17, 2009 Thank you! The code worked perfectly. Link to comment https://forums.phpfreaks.com/topic/149455-sessions-and-mysql/#findComment-786464 Share on other sites More sharing options...
shlumph Posted March 17, 2009 Share Posted March 17, 2009 Glad to hear I could help Link to comment https://forums.phpfreaks.com/topic/149455-sessions-and-mysql/#findComment-786827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.