Searching user data for a Session

Asked

Viewed 228 times

1

I’m making a site where several users can log in. I logged in for the login but I can’t find the other user data that is in the database. How can I do this?

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();

and 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;
  }

on the line logaUsuario($usuario['nome']); if I change name to email or any other bank data it changes there in my username.... but I can’t multiply the log($user['name']); to fill the data in the user profile page

  • 2

    It depends on what your database looks like. Edit the question and add the code you tried to do.

  • 1

    It also depends on what you’re saving in this session.

  • Just one question before displaying the code. I can store all the data that is in the user database in a session?

  • try to post code so we can help

  • 1

    @Francisvagnerdaluz Yes, but it’s not the right thing to do.

  • have function $user = searchUsuario($connection, $_POST['email'], $_POST['password']); if($user == null) { header("Location: ../index.php?login==0"); } Else { logaUsuario($user['name']); header("Location: ../internal/index.php"); } die();

  • mas não consigo multiplicar o logaUsuario($usuario['nome']); para preencher os dados na página de perfil do usuário Multiply as well ?

  • What is the code for the login function? If you can, please edit the question again by informing it helps us.

Show 3 more comments

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;
}

Would that be your condition

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");
}
  • yes Wéllingthon, thank you, I did this and there was no error. But how do I now stop to list on my profile page? Example on the profile page.php I want to put a <H1>user name</H1>, <p>user email</p>, <p>user id</p>, how can I do this separation?

  • you can do so <h1><?php echo $_SESSION['user_name']; ?></h1><p><?php echo $_SESSION['user_email']; ?></p><p><?php echo $_SESSION['user_id']; ?></p>

  • Man, thank you so much! Thanks so much, I was even losing sleep over this...rs.. How do I say here on the forum that your answer was correct?

Browser other questions tagged

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