嘿,我是PHP的初学者,我正在尝试创建一个登录表单,我已经创建了login.php和login_script.php。
现在我在login_script.php中检查我的数据库,如果输入的详细信息不正确,我想发送一条错误信息显示回login.php。
问题是我每次使用传递变量通过URL方法执行此操作时,我在login.php中收到错误消息
未定义索引'错误'
这是login_script.php -
<?php
require("includes/common.php");
$email = $_POST['e-mail'];
$email = mysqli_real_escape_string($con, $email);
$password = $_POST['password'];
$password = mysqli_real_escape_string($con, $password);
$password = MD5($password);
// Query checks if the email and password are present in the database.
$query = "SELECT id, email FROM users WHERE email='" . $email . "' AND password='" . $password . "'";
$result = mysqli_query($con, $query)or die($mysqli_error($con));
$num = mysqli_num_rows($result);
// If the email and password are not present in the database, the mysqli_num_rows returns 0, it is assigned to $num.
if ($num == 0) {
$error = "<span class='red'>Please enter correct E-mail id and Password</span>";
header('location: login.php?error=' . $error);
} else {
$row = mysqli_fetch_array($result);
$_SESSION['email'] = $row['email'];
$_SESSION['user_id'] = $row['id'];
header('location: products.php');
}
注意:这是在login.php-
中给出错误的行$error=$_GET['error'];