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
https://forums.phpfreaks.com/topic/124288-solved-_session-not-working/
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']}!";

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.