Jump to content

Problem inserting $_session variable


Eskimo887

Recommended Posts

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 [i]not[/i] 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?
Link to comment
https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/
Share on other sites

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.

Archived

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

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