Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 CGRRay

CGRRay
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 21 October 2006 - 02:41 PM

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.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 October 2006 - 08:20 PM

Just echo & set the value attribute of your hidden input field... but I don't actually see $idvar anywhere.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Rodger Holland

Rodger Holland
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 March 2007 - 02:08 AM

Just echo & set the value attribute of your hidden input field... but I don't actually see $idvar anywhere.


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

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 March 2007 - 02:20 PM

I don't know what you mean by "captured in the table".
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 Rodger Holland

Rodger Holland
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 March 2007 - 03:37 PM

I don't know what you mean by "captured in the table".


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

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 March 2007 - 04:58 PM

So you're saying that it doesn't make it into the $POST hash?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 Rodger Holland

Rodger Holland
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 10 April 2007 - 12:15 AM

So you're saying that it doesn't make it into the $POST hash?


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



#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 April 2007 - 11:48 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 Rodger Holland

Rodger Holland
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 April 2007 - 03:39 AM

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



#10 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 April 2007 - 11:41 AM

Not big on books, don't have an recommendations.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users