Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2016
    Posts
    14

    Unanswered: Check if a user is admin and echo

    Hi everyone, I'm a bit stuck not entirely sure if I'm doing this right. I have a table called users and a collumn called usertype. Want to check and see if it == 1 for the current logged in user. If so then echo something. THis returns an error. Any help most appriciated. Thanks

    PHP Code:
    <?php
    $sql 
    "
    SELECT users.usertype
    FROM users
    "
    ;
        if (
    $_SESSION['usertype']) == 1)

     {
     echo 
    'You are admin';
     }
    ?>

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ?
    so is usertype coming from a session variable declared/defined/set in another script
    OR
    is it supposed to be coming from a SQL table

    on the face of it sthe SQL is entiorely redundant as you don't use it anywhere. besides which even if you did use it in a db object it tells you no9thign about this user. if you want to find the current users permissions then you need to specify which users permissions you want.. which would mean using a where clause to limit to a specified user. granted that user may have been set in a session variable elsewhere, ferisntance when the user first authenticates themsleves.

    what error message is being reported, on what line

    I'm presuming you have turned on error reporting, ie set an appropriate error_reporting level
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2016
    Posts
    14
    Quote Originally Posted by healdem View Post
    ?
    so is usertype coming from a session variable declared/defined/set in another script
    OR
    is it supposed to be coming from a SQL table

    on the face of it sthe SQL is entiorely redundant as you don't use it anywhere. besides which even if you did use it in a db object it tells you no9thign about this user. if you want to find the current users permissions then you need to specify which users permissions you want.. which would mean using a where clause to limit to a specified user. granted that user may have been set in a session variable elsewhere, ferisntance when the user first authenticates themsleves.

    what error message is being reported, on what line

    I'm presuming you have turned on error reporting, ie set an appropriate error_reporting level


    usertype is the collumn in my database where i'm trying to declare it
    Below is my connection -
    Apologies for this I'm still fresh trying to learn this stuff on my own
    PHP Code:
    if(isset($_POST['login'])){

    $username mysqli_real_escape_string($con,$_POST['username']);

    $pass mysqli_real_escape_string($con,$_POST['pass']);

    $usertype mysqli_real_escape_string($con,$_POST['usertype']);

    $sel_user "SELECT * FROM users WHERE username='$username' AND password='$pass' AND usertype='$usertype'";

    $run_user mysqli_query($con$sel_user);

    $check_user mysqli_num_rows($run_user); 

  4. #4
    Join Date
    Jan 2016
    Posts
    14
    Quote Originally Posted by healdem View Post
    ?
    so is usertype coming from a session variable declared/defined/set in another script
    OR
    is it supposed to be coming from a SQL table

    on the face of it sthe SQL is entiorely redundant as you don't use it anywhere. besides which even if you did use it in a db object it tells you no9thign about this user. if you want to find the current users permissions then you need to specify which users permissions you want.. which would mean using a where clause to limit to a specified user. granted that user may have been set in a session variable elsewhere, ferisntance when the user first authenticates themsleves.

    what error message is being reported, on what line

    I'm presuming you have turned on error reporting, ie set an appropriate error_reporting level
    This in my connection file.
    error I get is
    PHP Code:
    Parse errorsyntax errorunexpected '==' (T_IS_EQUALin C:\wamp\www\pedalrevolution\extranet\index.php on line 45 
    It's the line with
    PHP Code:
    if ($_SESSION['usertype']) == 1
    PHP Code:
    $username mysqli_real_escape_string($con,$_POST['username']);

    $pass mysqli_real_escape_string($con,$_POST['pass']);

    $sel_user "SELECT * FROM users WHERE username='$username' AND password='$pass' usertype='$usertype";

    $run_user mysqli_query($con$sel_user);

    $check_user mysqli_num_rows($run_user);

    if(
    $check_user>0){

    $_SESSION['username']=$username;
    $_SESSION['usertype']=$usertype
    Basically was going to echo out links if usertupe is admin or = 1. Without trying to confuse things even more at this stage I would also need to run a check on one of the other liks to still make sure the user is = 1.

    Any help most appriciated by the way.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by TheTrooper View Post
    It's the line with
    PHP Code:
    if ($_SESSION['usertype']) == 1
    so... remove the first closing bracket.
    the PHP parsers is telling you where it gave up (in this case it realised there was a problem when it found the ==

    essentailly the parser read

    PHP Code:
    if ($_SESSION['usertype']) == true 
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •