我有一个包含“电子邮件、senha、apelido 和 data_criacao”列的表格。我使用 PHP 和 MySQL 创建了一个登录系统,现在我想显示一条带有用户昵称(即 Apelido)的消息,但我不能。我试了一整夜...
我试过获取,试过一段时间循环......
文件:登录.php
<?php
session_start();
include('conexao.php');
if(empty($_POST['email']) || empty($_POST['senha'])){
header('Location: index.php');
exit();
}
$email = mysqli_real_escape_string($conexao, $_POST['email']);
$senha = mysqli_real_escape_string($conexao, $_POST['senha']);
$query = "select apelido from cadastros where email = '{$email}' and
senha=md5('{$senha}')";
$result1 = mysqli_query($conexao, $query);
$row1 = mysqli_num_rows($result1);
if($row1 == 1){
$apelido = $row1['apelido'];
$_SESSION['usuario'] = $apelido;
header('Location: painel.php');
exit();
} else {
header('Location: index.php');
exit();
}
?>
文件:Panel.php
<?php
session_start();
include('verifica_login.php');
?>
<h2><?php echo $_SESSION['usuario']; ?></h2>
<h2> <a href="logout.php">SAIR</h2>
它应该显示“apelido”,但是当我提交表单时没有任何反应。如果我更改$_SESSION['usuario'] = $apelido;为$_SESSION['usuario'] = $email;,它可以正常工作,它会正常显示电子邮件
智慧大石