CGRRay Posted October 21, 2006 Share Posted October 21, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/ Share on other sites More sharing options...
fenway Posted October 22, 2006 Share Posted October 22, 2006 Just echo & set the value attribute of your hidden input field... but I don't actually see $idvar anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-112785 Share on other sites More sharing options...
Rodger Holland Posted March 15, 2007 Share Posted March 15, 2007 [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 Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-207684 Share on other sites More sharing options...
fenway Posted March 15, 2007 Share Posted March 15, 2007 I don't know what you mean by "captured in the table". Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-207987 Share on other sites More sharing options...
Rodger Holland Posted March 15, 2007 Share Posted March 15, 2007 [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 Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-208051 Share on other sites More sharing options...
fenway Posted March 15, 2007 Share Posted March 15, 2007 So you're saying that it doesn't make it into the $POST hash? Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-208130 Share on other sites More sharing options...
Rodger Holland Posted April 10, 2007 Share Posted April 10, 2007 [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 Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-225490 Share on other sites More sharing options...
fenway Posted April 11, 2007 Share Posted April 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-226690 Share on other sites More sharing options...
Rodger Holland Posted April 12, 2007 Share Posted April 12, 2007 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.... Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-227385 Share on other sites More sharing options...
fenway Posted April 12, 2007 Share Posted April 12, 2007 Not big on books, don't have an recommendations. Quote Link to comment https://forums.phpfreaks.com/topic/24657-solved-how-to-insert-a-session-variable-into-a-record/#findComment-227511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.