Error displaying value saved in $_SESSION in header

Asked

Viewed 24 times

-1

I wonder which part of my code is making a mistake, I’ve swept it and nothing, if I put in the echo $_SESSION['senha'] it displays the password, but if I put the name it displays the value 1.. I want to put type.. Welcome, echo $_SESSION['nome'];

"envia_login.php" page where the values of the login form field are received..

<?php

session_start();
header('Content-Type: text/html; charset=utf-8');
include("conexao.php");

if(empty($_POST['nome']) || empty($_POST['senha'])){
    header('location:chat_login.php');
    exit();
}

$nome = mysqli_real_escape_string($conn, $_POST['nome']);
$senha = mysqli_real_escape_string($conn, $_POST['senha']);

$query = "select * from usuarios where nome = '$nome' and senha = '$senha'";

$result = mysqli_query($conn, $query);
$row = mysqli_num_rows($result);


if($row == 1){
    $_SESSION['nome'] = $nome && $_SESSION['senha'] = $senha;

    //ESSE TRECHO ABAIXO FIZ VERIFICAÇÃO DE NÍVEL DE USUÁRIOS PARA REDIRECIONAR A PÁGINAS DIFERENTES------------! vou usar futuramente.
    while ($verifica_nivel = mysqli_fetch_array($result)) {

            $nivel = $verifica_nivel['nivel'];
            if ($nivel == 1) {
                header('location: chat_home.php');
            }else{
                header('location: chat_home.php');
            }

    }
}

else{
    echo "<script>alert('USUÁRIO NÃO CADASTRADO OU DADOS INVÁLIDOS!');</script>";
    echo "<script>window.location='chat_login.php';</script>";
    exit();
}
?>

Page "chat_home.php"

Log in with check login that checks empty fields and redirects immediately.

<?php
session_start();
include("verifica_login.php");
?>

Excerpt from the code I’m inserting echo $_SESSION

<i id="title-header"><i class="medium material-icons">forum</i> 
    <strong>SUPORTE TI</strong>
</i>
     <p>Bem Vindo, <b><?php echo $_SESSION['nome']; ?></b></p>

It is exhibiting as follows.... Welcome, 1

1 answer

0

The way you did the assignment will not work because you are making a condition. Remove the && and make assignment as in the example below.

$_SESSION['nome'] = $nome;
$_SESSION['senha'] = $senha;

Browser other questions tagged

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