I have a login system, which each user is redirected to a specific page. In my database table I have the columns name, user, password and level.
I would like when the user logs in, the name registered in the database appears on your welcome page.
The echo
part has already been solved and is already printed on the screen, but I can only with the variable usuario
, the data in the nome
column can not print on the screen.
This is my file that validates the login:
<?php
require ("db.php");
$usuario = $_POST['inputUsuario'];
$senha = md5($_POST['inputPassword']);
$query = mysqli_query($conn,"SELECT * FROM usuarios WHERE usuario = '$usuario' AND senha = '$senha'");
$row = mysqli_num_rows($query);
$dados = $query->fetch_array();
if ($row > 0){
if($dados['nivel'] == 1){
session_start();
$_SESSION['usuario'] = $_POST['inputUsuario'];
$_SESSION['senha'] = $_POST['inputPassword'];
header('Location: usuarios/usuario1.php');
}else if($dados['nivel'] == 2){
session_start();
$_SESSION['usuario'] = $_POST['inputUsuario'];
$_SESSION['senha'] = $_POST['inputPassword'];
header('Location: usuarios/usuario2.php');
}else if($dados['nivel'] == 3){
session_start();
$_SESSION['usuario'] = $_POST['inputUsuario'];
$_SESSION['senha'] = $_POST['inputPassword'];
header('Location: usuarios/usuario3.php');
}
}else{
header('Location: index.php?msg=1');
}
?>
Location where you are trying to print the name:
<h2><?php echo "Bem vindo ". $_SESSION['nome'];?></h2>