What is the proper format for this code? There seems to be a problem with the session variable

<?php $r = mysql_query("select * from tbl_student_master where email='@$_SESSION[email]'") or die(mysql_error());

First off, please note that mysql_* functions are soon to be removed from the standards.

To answer your question, you can do the following:

<?php

    $email = $_SESSION['email'];

    $query = "SELECT * FROM tbl_student_master WHERE email='$email'";
    $result = mysql_query($query) or die(mysql_error());

Or just the following:

<?php

    $email = $_SESSION['enail'];

    $query = "SELECT * FROM tbl_student_master WHERE email='$_SESSION[email]'";
    $result = mysql_query($query) or die(mysql_error());

you could also check is session email is set

if(isset($_SESSION['email']){
    $email = $_SESSION['email'];

    $query = mysql_query("SELECT * FROM table_name WHERE email = '$email' ");
    if(!$query){
        die('Query Failed!'.mysql_error());
    }

    $return = mysql_fetch_assoc($query);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.