Jump to content

Sessions and mysql


frankerpulten

Recommended Posts

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

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

Archived

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

×
×
  • Create New...

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.