SQL and php IF statement help


Im having an issue with my sql statement. I need to be able to identify a user after he logs in based on a database system. Im trying to create an if statement that if it returns true then the user level will become 1 and if it returns false the the user level becomes 2. So department head is in the second table, and IF employee.supervisor_id equals the department.department_head it should be true. But if its false then it will return the 0. However i cant think of a logical way that I can fit the $username variable that the user inputs into the if statement. Here is the code:

if($dbConn->query(“SELECT department.department_head,employee.supervisor_id, employee.employee_id,
FROM employee
INNER JOIN department ON ‘employee.supervisor_id’ = department.department_head
WHERE department.department_head = $username;”)== “TRUE”) {
} else {
Im not entirely sure if it is correct syntax but I cant find many ways to create an if statement in that shape. thanks in advance.


Prepared statements.

What’s with the extra closing brackets?

You need to know the relationship between the tables. As it looks now, you are trying to match a username to an id.