php - 在登录中的PHP“未定义变量”错误
问题描述
当我登录系统时,我得到一个错误。我尝试使用“电子邮件”而不是 id 来修复它,但它不起作用。我是 PHP 新手。我该如何解决这个问题?
注意:未定义变量:第 161 行 C:\xampp\xAmmp\htdocs\project\index.php 中的 id
索引.php
...
<?php if ($id == $_SESSION['id'] ) { ?>
<h4>
<span style="font-family:\'Pacifico\', cursive;">Welcome, </span>
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="glyphicon glyphicon-user"></i> <?php echo explode(' ', $_SESSION["name"])[0] ?> <span
class="caret"></span>
</button>
<ul class="dropdown-menu">
...
登录.php
<?php
include('conn.php');
session_start();
$error = "";
//email entered by user
$email = mysqli_real_escape_string($link, $_POST['email']);
//password entered by user md5 method is used for password encryption
$password = md5(md5($_POST['email']) . $_POST['password']);
//Query to see whether user and password combination exists
$query = "SELECT * FROM users WHERE email = '$email' AND password = '$password' LIMIT 1";
if ($result = mysqli_query($link, $query)) {
if ($row = mysqli_fetch_array($result)) {
$_SESSION['name'] = $row['name'];
$_SESSION['email'] = $row['email'];
$_SESSION['dob'] = $row['dob'];
if (isset($row['rest']))
$_SESSION['rest'] = $row['rest'];
} else {
$error .= "User does not exists with that combination of email and password.<br />";
}
} else {
$error .= "User does not exists with that combination of email and password.<br />";
}
if ($error != "")
echo '<div class="alert alert-danger alert-dismissible fade in" role="alert" style="margin-top: 20px">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
' . $error . '</div>';
?>
解决方案
推荐阅读
- android - Android Studio 3.1 拒绝工作
- javascript - 在设置的间隔上设置计数
- bots - 单击网页上的按钮
- vba - 工作表中多个工作表的 VBA 循环
- android - 未解决的参考 GoogleSignIn
- javascript - 来自现有对象的新 ES6 类实例
- c++ - 使用 CMake GUI 将 Contrib 模块添加到 OpenCV 3 的说明
- oracle - 插入性能 - Oracle 与 Postgres
- javascript - javascript c、e、t、q、w、A、u、B、m、h、d、C、r、x、D、y 的问题
- python - Python:用户输入要写入/写入的文件名。然后程序打开/读取