phplearner2008 Posted September 15, 2008 Share Posted September 15, 2008 Hi, I am trying to store value on SESSION variables, but it does not output anything! here's my code <?php session_start(); $dbhost = "localhost"; $dbuser = "root"; $dbpass = "password"; $dbname = "matrimonial"; $con = mysql_connect($dbhost,$dbuser,$dbpass) or die("Error connecting to mysql"); mysql_select_db($dbname,$con); $LOGIN = $_POST['LOGIN']; $PASSWORD = $_POST['PASSWORD']; $_SESSION['MYLOGIN'] = $_POST['LOGIN']; //echo "$LOGIN"; echo "$_SESSION['MYLOGIN']"; When I tried to store $_POST['LOGIN'] in $_SESSION['MYLOGIN'] and echo, it does not output anything whereas when i stored it in $LOGIN, i got the correct output. Why is my $_SESSION not working. Thanks. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 Are you sure that $_POST['LOGIN'] actually has a value. Put this on the page: print_r($_POST); It should list all the values that have been sent by the form. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 15, 2008 Share Posted September 15, 2008 Using this statement <?php echo "$_SESSION['MYLOGIN']"; ?> should generate a syntax error. Use: <?php echo $_SESSION['MYLOGIN']; ?> this instead. Ken Quote Link to comment Share on other sites More sharing options...
phplearner2008 Posted September 15, 2008 Author Share Posted September 15, 2008 Thank you ken, the problem was with double quotes. I removed it and it is working fine. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 Ah, of course. Just for future reference phplearner2008, if you need to echo any array inside a string you can break out of the string or use curly braces. echo "Hello and welcome back ".$_SESSION['user']."!"; OR echo "Hello and welcome back {$_SESSION['user']}!"; Quote Link to comment Share on other sites More sharing options...
phplearner2008 Posted September 15, 2008 Author Share Posted September 15, 2008 Thanks ProjectFear for your valuable information. Quote Link to comment 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.