-2

hi i want to start a session of user but i am unable to do that. i have see examples of it also but my problem is still the same. i am getting this error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a2277283/public_html/scripts/login.php on line 11

here is my code

<?php
    ob_start();
    session_start();
    include 'db.php';
    if (isset($_POST['submit'])) {
        echo $email = $_POST['user_email'];
        $sql = "select * from user where `user_email` = '$email'";
        if (mysql_query($sql)) {
            $_SESSION['email'] = $email;
            echo "$_SESSION['email']";
        }
    }
?>
Usman Riaz
  • 2,920
  • 10
  • 43
  • 66
  • 2
    just `echo $_SESSION['email'];` without double quotes –  Jul 25 '13 at 10:39
  • 2
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jul 25 '13 at 10:41

2 Answers2

1

the problem is:

echo "$_SESSION['email']";

Use without quotes like:

echo $_SESSION['email'];

or

echo "$_SESSION[email]";

or

echo "{$_SESSION['email']}";
Joshua Kissoon
  • 3,269
  • 6
  • 32
  • 58
0

Echo the session variable like this: echo "{$_SESSION['email']}"; as described at the PHP Docs

kinkee
  • 368
  • 2
  • 12