Eskimo887 Posted July 4, 2006 Share Posted July 4, 2006 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 7Where 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? Quote Link to comment https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/ Share on other sites More sharing options...
kenrbnsn Posted July 4, 2006 Share Posted July 4, 2006 The session array is [color=red][b]$_SESSION[/b][/color], not $_session. PHP is case sensitive.Ken Quote Link to comment https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/#findComment-52733 Share on other sites More sharing options...
Eskimo887 Posted July 4, 2006 Author Share Posted July 4, 2006 PHP may be case sensitive, but my typing isn't. I do have the $_SESSION as caps. :P Quote Link to comment https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/#findComment-52735 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2006 Share Posted July 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/#findComment-52737 Share on other sites More sharing options...
hitman6003 Posted July 4, 2006 Share Posted July 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/#findComment-52739 Share on other sites More sharing options...
Eskimo887 Posted July 4, 2006 Author Share Posted July 4, 2006 Yes, I forgot the session_start(); at the top of the page....it works now. :-[ Quote Link to comment https://forums.phpfreaks.com/topic/13608-problem-inserting-_session-variable/#findComment-52740 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.