Jump to content

[SOLVED] How to insert a session variable into a record


CGRRay

Recommended Posts

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.
Link to comment
Share on other sites

  • 4 months later...
[quote author=fenway link=topic=112238.msg455934#msg455934 date=1161548455]
Just echo & set the value attribute of your hidden input field... but I don't actually see $idvar anywhere.
[/quote]

I have an issue very similar to CGRay, and tried echoing without any luck. I will leave out the majority of the code, and get to the insert code---but I have verified that the session variable $Gender is reaching this page.

<input type="hidden" name="table" value="results_fin" />
<input type="hidden" name="Gender" value="<? echo "$Gender"; ?>" />

And Gender is a properly formatted field in results_fin.

But the variable is not being captured in the table.

Any other thoughts, or what am I screwing up.

Thanks
Link to comment
Share on other sites

[quote author=fenway link=topic=112238.msg552764#msg552764 date=1173968423]
I don't know what you mean by "captured in the table".
[/quote]

I wish to record/store the global variable in the table, or insert the session variable into the table. Sorry, I am a novice in using php and MySQL so my terminology may be a bit off. My primary programmer on the research project is swamped, and I am trying to fix the problem myself.

Thanks in advance for your assistance,

Rodger
Link to comment
Share on other sites

  • 4 weeks later...
[quote author=fenway link=topic=112238.msg552908#msg552908 date=1173977882]
So you're saying that it doesn't make it into the $POST hash?
[/quote]

Sorry to have not replied earlier, but I had rotator cuff surgery and was unable to do very much for a while.

I am sorry, but I am a novice trying to patch some work by the "pro" who is no longer available. I plan to take some time this summer (since I will not be teaching) to become more proficient in php, but the term $POST hash is foreign to me. All I can say is that when I attempt to post to the table, the $Gender variable is not being recorded (posted) into that table. I think that is what you mean, but I apologize in advance if it is not.

And FYI, I have verified that the variable is properly defined in the table, and it has the same form as it does and is being captured in the Gender table.

Rodger

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.