0

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());
3
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by gabrielcastillo
0

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());
0

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);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.