0
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 logged in, the registered name appeared in the database on your welcome page.
The part of echo
already solved and is already printed on the screen, but only with the variable usuario
, the data in the column nome
I can’t print on screen.
This is my log-in validation file:
<?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');
}
?>
Where to try to print the name:
<h2><?php echo "Bem vindo ". $_SESSION['nome'];?></h2>
As an aside and not directly focused on the question, consider protecting your page against mysql Injection Attacks, validating input data or using Prepared statements. Where is the
echo
? Put this code in too– Isac
but where is the error? I’m not seeing you pass the name column anywhere! If possible, put the part code where you are trying to print the data
– Diego Lela
Thanks for the tip Diego, I tried to pass the name column data using mysqli_fetch_assoc and did not give. The way the code looks, how could I include a variable for the name column? Sorry for the questions, but this is my first file that I work with php and database, and I have virtually no experience at all.
– Elicarlos