0
votes

In my project, I have two tables. They are login and employee table.

Employee table contains name, NIC etc. and login table has NIC, password.

NIC is username of the system. I wanted to know how to retrieve logger name from the session. This is the code I have added to the system, but it shows error as systax error. Could anyone help me to solve this?

<?php
   $sql = 'SELECT  tbl_employee.Fname
   FROM tbl_login , tbl_employee
   WHERE  tbl_employee.NIC =  tbl_login .$_SESSION['username'] ';
?>
2
You should always include the error message, if available, when posting a question. Also prepared statements are recommended. I think your error is the single quotes but hard to know; could just as easily be a SQL syntax error... - chris85

2 Answers

0
votes

You don't need to refer to tbl_login (you already have the NIC in your $_SESSION['username'] var ) and if NIC is a string you should enclose it in quotes

<?php
    $sql = 'SELECT  tbl_employee.Fname
    FROM tbl_employee
    WHERE  tbl_employee.NIC = "' . $_SESSION['username'] . '"';
 ?>
0
votes

Try this. This should work. You can capture the session in toa variable

    $sess = $_SESSION['username'];        
    $sql = "SELECT  tbl_employee.Fname
       FROM tbl_login , tbl_employee
       WHERE  tbl_employee.NIC =  { 'tbl_login' .$sess } ";

Or, If you dont want to use one more variable,

    $sql = "SELECT  tbl_employee.Fname
       FROM tbl_login , tbl_employee
       WHERE  tbl_employee.NIC = tbl_login" .$_SESSION['username'];