Answered
How do I insert a session variable into a record?
I can’t figure out how to insert the value passed by a session variable into a record.
I have a form I want to use to insert a record. I pass session variables to this page and want to insert one of them into the record. The session information is:
session_start();
{
$_SESSION['usename'] = $_POST['username'];
$idvar = $_SESSION['id'];
}
$_SESSION[‘id’] is the user_id that I want to insert into the record.
I know $idvar is getting to the page with the form because I can echo it.
The insert code looks like this:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "register")) {
$insertSQL = sprintf("INSERT INTO h_genres (user_id, username, contrib_to, Advertising, Annual_Reports, Leader_Content, Member_Content, Brochures) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['user_id'], "int"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['contrib_to'], "text"),
GetSQLValueString(isset($_POST['Advertising']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Annual_Reports']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Leader_Content']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Member_Content']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['Brochures']) ? "true" : "", "defined","'Y'","'N'"));
mysql_select_db($database_hauw, $hauw);
$Result1 = mysql_query($insertSQL, $hauw) or die(mysql_error());
}
I have a hidden field for the user_id:
<input name="user_id" type="hidden" id="user_id" />
I think I need to get the value in $idvar into user_id but I don’t know how.
Any help is appreciated.
