Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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