Ok, the title is not exactly excellent, so let me explain the situation here. I use a javascript plugin to make suggestions to the user while they type in a form field. This javascript file uses a PHP file to know the values to suggest. This PHP file queries the database to return these values.
What I would like to do is to return different results based on the user who is connected, but when I try to do this, everything stops working. It only works if I specify one single query.
After the connection to the database, here is the code:
<?php
$query = $_GET['query'];
$users=array();
if ($_SESSION['privilege'] == 100) {
$sql = "SELECT username FROM users WHERE username LIKE 'something'";
} else {
$sql = "SELECT username FROM users WHERE username LIKE 'somethingelse'";
}
$result = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_array($result))
{
$users['suggestions'][] = stripslashes($row['username']);
}
$users['query'] = $query;
echo json_encode($users);
?>
It looks like the script is not able to check the value of $_SESSION[‘privilege’], but it should, because I am able to check it inside other pages. This script works if I delete the if then else.
Any ideas?