0
Good afternoon, I am developing a website for my TCC, I am still apprentice in developing sites with php.
I’m trying to get the user to enter your page to receive welcome with your name searched in mysql, follow photo 1.
But I do not want the email to stay, but the name of the user who signed in to your account. First, I created a session to check if the user is logged in to your account.
<?php
session_start();
if(!isset($_SESSION["email"]) || !isset($_SESSION["senha"])) {
// Usuário não logado! Redireciona para a página de login
header("Location: index.php");
exit;
}
?>
Then follows below the H2, showing the welcome.
<h2>Bem vindo aluno! <?php echo $_SESSION['email']; ?></h2>
I used a SESSION to call the email just for testing, but I want to call the user name being the attribute "name" in mysql. What easier way can I make it?
Taking into account that when putting the name instead of email, it does not return anything in the welcome message.
NOTE: Adding the PHP code, which makes the query in the database, and had forgotten to add in the question. Follow the code below:
<?php
session_start();
include("conexao.php");
$email = $_POST['email'];
$senha = $_POST['senha'];
$sql_logar = "SELECT * FROM aluno WHERE email = '$email' AND senha = '$senha'";
$exe_logar = mysqli_query($conection, $sql_logar) or die (mysqli_error());
$num_logar = mysqli_num_rows($exe_logar);
if ($num_logar == 0){
$_SESSION['msg'] = "<div class='alert alert-danger'>Login ou senha incorreto!</div>";
header("Location: index.php?login");
}
else{
//Cria a sessão e verifica tipo de login
while($percorrer = mysqli_fetch_array($exe_logar) ){
$tipo = $percorrer['tipo'];
}
$_SESSION['tipo'] = $tipo;
$_SESSION['email'] = $email;
$_SESSION['senha'] = $senha;
$_SESSION['nome'] = $nome;
if($tipo != "2"){
header("Location: aluno.php");
}else{
header("Location: administrador.php");
}
}
?>
https://celke.com.br/artigo/sistema-de-login-com-php-e-mysqli
– ElvisP
The login system already made friend, the topic is another;
– Matheus
@Hermetobermudez , you just want to show the Name instead of the email, right ? Being that, it’s simple. Just you, assign to a $_SESSION['name'] the user name (as you do with the email) and display that $_SESSION['name'] or instead of $_SESSION['email']. Try to edit your question and add to it the query you use to fill out the SESSIONS. So we can visualize and help you in the best way.
– Gato de Schrödinger
This Gambi, I thought so, I tried but it didn’t work, because the SESSION I assign in the email is just for verification, how can I check the name of the user who entered.. why if you just put a $_SESSION['name'] in nothing too :/
– Matheus
Put in the question the code with the query you fill the SESSION, please.
– Gato de Schrödinger
The only query I use is the one I quoted above, then it’s just body with the site, which is the H2 of welcome,
– Matheus
Quoted where ? Can’t see, sorry.
– Gato de Schrödinger
Let’s go continue this discussion in chat.
– Gato de Schrödinger