Jump to content


Photo

Problem inserting $_session variable


  • Please log in to reply
5 replies to this topic

#1 Eskimo887

Eskimo887
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 July 2006 - 02:33 AM

On my website, users can log in and their id is stored in a session.  I want to insert this id, when they fill in a form, as a row in the database.

Eg.

member_id    opinion
      1              7

Where the member_id is not typed in by the user, but is inserted using the session variable.

I have tried a couple different methods:

1. Putting the session as a local variable - $id = $_session['id'];
Then in the insert query - INSERT INTO members SET " . "member_id='$id'";

2. Having the $session['id']; straight in the insert queyr - INSERT INTO members SET " . "id='$_session['id']";

But neither of these methods work.

My id column is set as an integer, and so it only shows a 0 on every row.  I have also tried text and VARCHAR with the same negative result.

What can I do to make this thing work?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 July 2006 - 02:35 AM

The session array is $_SESSION, not $_session. PHP is case sensitive.

Ken

#3 Eskimo887

Eskimo887
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 July 2006 - 02:38 AM

PHP may be case sensitive, but my typing isn't.  I do have the $_SESSION as caps.  :P

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 July 2006 - 02:40 AM

Do you call session_start() at the start of each script where you use the $_SESSION array?

Please post the relevant sections of your scripts.

Ken

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 July 2006 - 02:43 AM

Double check how you have typed each instance of $_SESSION...in your post you typed it three different ways.  Also, make sure that session_start(); is at the top of your page.

If you are sure that you are always using $_SESSION and that session_start(); is at the top of your page, then echo your sql statement to see what it looks like.  It may be an error in the configuration of your db field, among many other things...

Make sure that you have "or die(mysql_error())" on the end of your "mysql_query" line too.  If you don't have that then you won't know if there are any errors.

#6 Eskimo887

Eskimo887
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 July 2006 - 02:44 AM

Yes, I forgot the session_start(); at the top of the page....it works now.  :-[




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users