Searching for user data from a session [closed]

1

I'm making a website where multiple users can log in. I logged in but I can not get the other user data that is in the database. How can I do this?

I have the function

$usuario = buscaUsuario($conexao, $_POST['email'], $_POST['senha']);

  if($usuario == null) {

    header("Location: ../index.php?login==0");
  } else {

    logaUsuario($usuario['nome']);
    header("Location: ../interno/index.php");
  }

die();

I also have:

function buscaUsuario($conexao, $email, $senha) {

    $query = "select * from usuarios where email='{$email}' and senha='{$senha}'";
    $resultado = mysqli_query($conexao, $query);
    $usuario = mysqli_fetch_assoc($resultado);
    return $usuario;
  }

In the logaUsuario($usuario['nome']); line if I change my name to email or any other data from the database it changes there in my logged_user .... but I can not multiply the logaUsuario ($ user ['name']); to populate the data on the user's profile page

    
asked by anonymous 17.08.2017 / 22:35

1 answer

0
// Edita a função logaUsuario e adicione os campos que,
// Você deseja salvar na SESSION
function logaUsuario($ID, $Nome, $Email/*, $Campo1, $Campo2, etc.. */)
{
    $_SESSION['user_id'] = $ID;
    $_SESSION['user_name'] = $Nome;
    $_SESSION['user_email'] = $Email;
    // Adicione também exemplo
    // $_SESSION['Campo1'] = $Campo1;
    // $_SESSION['Campo2'] = $Campo2;
}

Your condition would look like this

if($usuario == null) {
    header("Location: ../index.php?login==0");
} else {
    // Chame a função passando os parametros necessarios
    logaUsuario($usuario['id'],$usuario['nome'],$usuario['email']);
    header("Location: ../interno/index.php");
}
    
18.08.2017 / 13:52