Jump to content

[SOLVED] $_SESSION not working


phplearner2008

Recommended Posts

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.

Link to comment
Share on other sites

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']}!";

Link to comment
Share on other sites

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.