您好,每当我在我的网站上按下登录按钮时,我都会收到此错误:
Notice: Undefined index: active in C:\xampp\htdocs\repute-multipurpose-theme-v1.3\theme\login.php on line 14
我想知道你们是否知道如何解决这个问题。我一直在阅读有关 isset
函数的内容,但我在第 14 行尝试了该函数,但它又出现了另一个错误,因此它似乎不起作用。
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($conn,$_POST['username']);
$mypassword = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
$_SESSION['login_user'] = $myusername;
header("location: index2.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
最佳答案
您尚未在查询中选择事件
列。您只有 customer_id
:
$sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
此外,您很容易出现 SQL Injection 。
<小时/>以防万一,您不知道 Undefined Index错误。
关于PHP登录表单错误未定义索引: active,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49351056/