0
I put the method session_start()
to make the user name appear on the screen when he logs in to the following pages, but I wanted to put his "name" instead of "email" follows the code I did:
Code to validate user input.
<?php
session_start();
require_once("conexao.php");
$conn = mysqli_connect('localhost', 'root', '') or die ( mysqli_error() );
mysqli_select_db($conn, 'projeto') or die ( mysqli_error() );
$user = $_POST['email'];
$pwd = $_POST['senha'];
$query = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM nutricionista WHERE email = '$user' AND senha ='$pwd'"));
if($query == 1){
$_SESSION['email'] = $user;
$_SESSION['senha'] = $pwd;
header("location: menuNutricionista.php");
} else {
echo "<script>alert('Dados informados incorretamente!');history.back();</script>";
}
?>
Here is the page HTML where it goes bem-vindo + nome do usuário
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../css/style.css">
<script type="text/javascript" src="../css/script.js"></script>
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<link rel="shortcut icon" href="imagens/favicon.png" />
<?php
session_start();
if((!isset ($_SESSION['email']) == true) and (!isset ($_SESSION['senha']) == true))
{
unset($_SESSION['email']);
unset($_SESSION['senha']);
header('location:index.php');
}
$logado = $_SESSION['email'];
?>
</head>
<body>
<img id="emblema" src="../imagens/emblema.png">
<div class="div-logado">
<?php echo"Bem-vindo </br>$logado "; ?>
</div>