-2

Im trying to recall the logged in user's userlevel from mysql for the if function that determines whether to show the admin panel or not. if anyone can help me and tell me what i was missing so i can learn from this experience, that would be great!

here is my code... it's not working :(

$loginLink = '<a class="load" href="login.php">Log In</a> &nbsp; | &nbsp; <a class="load" href="signup.php">Sign Up</a>';
if($user_ok == true) {
$query = mysqli_query($db_conx, $sql);
$row = mysqli_fetch_row($query);
$sql = "SELECT id FROM notifications WHERE username='$log_username' AND date_time > '$notescheck' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$userlevel = "SELECT userlevel FROM users WHERE username='$log_username' LIMIT 1";    
if ($userlevel == 'admin' && $userlevel == 'owner') {
    $adminPanel = '<a class="load" href="adminpanel.php">Admin Panel</a>';
}else {
    $adminPanel = '&nbsp;';
}

?>
Snazzie
  • 197
  • 1
  • 3
  • 12
  • why is there 2x `$query = mysqli_query($db_conx, $sql);`? you also have a LOT of missing code. – Funk Forty Niner Jun 12 '15 at 14:26
  • 1
    *"it's not working :("* isn't much of an indication. Here, debug it. Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Jun 12 '15 at 14:29
  • 1
    You have a history of off-topic or heavily questions and are at risk of losing your question-asking privileges. [You should read this before you post your next one](http://s.tk/onhold). – John Conde Jun 12 '15 at 14:38
  • and this makes so sense at all `if ($userlevel == 'admin' && $userlevel == 'owner')` – Funk Forty Niner Jun 12 '15 at 14:39

1 Answers1

1

You miss actually getting the return values, especially with the statement $userlevel = "<some query>"; where you forget even executing the query.

Side note: I don't know where the value of $log_username comes from, but if it's anywhere out of your control: sanitize it first or use prepared statements (which is also a good idea if they are in your control, just for good measure).

Daan Wilmer
  • 937
  • 4
  • 13