-1
 $sql= 'select employee.id AS ID,CONCAT(employee.fname," ",employee.lname) AS Name, IF(loan.status= "unpaid",loan.installment,0) AS Loan where employee.user = "$name"';  

This doesn't show the result from the table. because this query is showing no match . I think putting "$name" in double quote is the error.

   $sql= "select employee.id AS ID,CONCAT(employee.fname," ",employee.lname) AS Name, IF(loan.status= 'unpaid',loan.installment,0) AS Loan where employee.user = '$name'"

in this case putting 'unpaid' in single quote doesn't show result for this column

i tried employee.user = ''' $name''' employee.user = "'$name'" none of these work.. please help

Israt
  • 55
  • 8
  • 1
    This question isn't clear. What errors do you get? *How* is this code not working? What is the value of `$name`? Where is it defined? It also looks like you are wide open to SQL injections. – John Conde Feb 03 '18 at 20:17
  • $name = $_SESSION['id'] – Israt Feb 03 '18 at 20:21
  • $sql= 'select employee.id AS ID,CONCAT(employee.fname," ",employee.lname) AS Name, IF(loan.status= "unpaid",loan.installment,0) AS Loan where employee.user = "$name"'; this doesn't show the result from the table ... But shows no error... employee.user = ' "$name" ' gives syntax error ... – Israt Feb 03 '18 at 20:24
  • Use `mysqli`'s prepared statements with placeholders. – mickmackusa Feb 03 '18 at 22:43

1 Answers1

0

The quotes sequence seems correct but You missed the from clause

$sql= "select employee.id AS ID,CONCAT(employee.fname, ' ' ,employee.lname) AS Name, 
    IF(loan.status = 'unpaid',loan.installment,0) AS Loan 
    FROM   employee
    INNER JOIN loan on loan.your_key1 = employee.your_key2
    where employee.user = '$name'";

You must assign the proper column name to your_key1 and your_key2 for JOIN

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107