0

So i have a page where there is a button when clicked it takes u to an admin page. if u click it first takes u to a admincheck code before bringing u to the adminpage. In that admincheck page it should let admins go through and normal users redirected back. It doesnt work i dont know why

here is the admincheck code:

    <?php
include "dbconnection.php";
include "login.php;"
$query = "SELECT * FROM gebruikers WHERE gebruikerID = $userid";
$result = mysqli_query($conn, $query);
$count = $conn->affected_rows;
if($row['admin']=='Ja'){
    header("location: contactregister.php"); 
    }       
else{
    $message = "You shall not pass!";
    echo "<script type='text/javascript'>alert('$message');</script>";
    header("location: home.php");
    }
?>

Did i do anything wrong in that code??

ViPZoMbie1
  • 13
  • 5
  • What do you mean it doesnt work? Does it allow everyone? No one? A PHP error? – Ice76 Dec 15 '17 at 01:18
  • Oh im sorry Instead of checking if the user is an admin or not it just keeps going back to the page with the button so in the if else statement the else statement keeps being excecuted but that shouldnt happen since im logged in with an admin account. – ViPZoMbie1 Dec 15 '17 at 01:25
  • @ViPZoMbie1 use `var_dump($result);` and tell me the result – Bluetree Dec 15 '17 at 02:45
  • It prints NULL on my screen so its not picking the value from the db? – ViPZoMbie1 Dec 15 '17 at 02:49
  • @Bluetree if i put it in another place it tells me this... object(mysqli_result)#1 (5) { ["current_field"]=> int(0) ["field_count"]=> int(13) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) } – ViPZoMbie1 Dec 15 '17 at 02:52
  • @ViPZoMbie1 did you put `var_dump($result);` after `$result = mysqli_query($conn, $query);`? If yes try to also `var_dump($userid)` after `var_dump($result);` – Bluetree Dec 15 '17 at 03:05
  • @Bluetree wow that is weird it also says null??? but before i could echo the userid! – ViPZoMbie1 Dec 15 '17 at 03:13
  • 1
    @ViPZoMbie1 Good. so we know that the problem is `$userid` and it's getting `null` value. You have a problem in your `login.php` . – Bluetree Dec 15 '17 at 03:17
  • I've checked and it works on all other pages it should work here – ViPZoMbie1 Dec 15 '17 at 03:31

0 Answers0