How to pull data from a login

Asked

Viewed 103 times

1

I need to pull the value of the 'level' that is in the bank because I am setting in some pages the question of access permission , only that I am not able to pull this data from the table . Can someone please help me ?

Follow my connection code :

 <?php 
session_start();
            $serverName = "";
            $connectionInfo = array( "Database"=>"", "UID"=>"", "PWD"=>"" );
            $conn = sqlsrv_connect($serverName, $connectionInfo);
                 if ($conn === false) {
                  die(print_r(sqlsrv_errors(), true));
}

 $user = $_POST['email'];
 $password = $_POST['password'];

 $query = ("SELECT LOGIN,SENHA,NIVEL FROM NOME_TABELA WHERE LOGIN LIKE '$user' AND SENHA LIKE '$password'");
 $params = array(); 
 $options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
  $stmt = sqlsrv_query($conn, $query, $params, $options);
  $row_count = sqlsrv_num_rows($stmt);
        if ($row_count > 0) {
               session_start();
               $_SESSION['email'] = $user;
               $_SESSION['password'] = $password;
                    header('location:inicio.php');
    }
        else {
    //Destrói
    session_destroy();

    //Limpa
    unset ($_SESSION['email']);
    unset ($_SESSION['password']);


    //Redireciona para a página de autenticação
    header('location:index.php');

}
?>



  • Friend, put the code in the question and not a print

  • I was not knowing how to format so I had sent via photo , but it has been changed

  • can better explain the "I’m not getting to pull this dice from the table"? what happens, some mistake?

  • So, I have 3 columns in my table ( User / password / level ) I need the variable "level" that is associated with the user in order to be able to restrict access in some pages. Only I can’t pull this value . It does not return to anything . to learning PHP now , I’m kind of layman . Ai to hit me to pull this data .

1 answer

0


Create a variable by associating user data to an array and take the NIVEL value:

if ($row_count > 0) {
   $dados = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
   $_SESSION['email'] = $user;
   $_SESSION['password'] = $password;
   $_SESSION['nivel'] = $dados["NIVEL"];
   header('location:inicio.php');
}else{
   ...
}

Documentation

  • 1

    Thanks man It worked here .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.