Jump to content

Archived

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

CGRRay

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

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.

Share this post


Link to post
Share on other sites
Just echo & set the value attribute of your hidden input field... but I don't actually see $idvar anywhere.

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
I don't know what you mean by "captured in the table".

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
So you're saying that it doesn't make it into the $POST hash?

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
You post to a script, and then run a mysql statement to insert records into a table... all of the fields make it into the $_POST hash, just wanted to see whether Gender was in there.

Share this post


Link to post
Share on other sites
Thanks for your attempted help, but I finally got the "pro" to correct the problem. I still plan on studying this summer.  I have Ulman's PHP and MySQL book. What would you suggest for a novice whose primary skills are Visual Basic and Microsoft Access???

Thanks again....

Share this post


Link to post
Share on other sites
Not big on books, don't have an recommendations.

Share this post


Link to post
Share on other sites

×

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.