PHP登录表单错误未定义索引: active

标签 php mysql sql html

您好,每当我在我的网站上按下登录按钮时,我都会收到此错误:

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/

相关文章:

php - UPS API 包括正确的 WSDL 文件和端点

mysql - 在 MySql 中快速搜索邮政编码

mysql - 两行数据合二为一

子查询中的 SQL 多个别名

javascript - PHP + JS + AJAX : Unexpected token { in JSON

php - file_get_contents() 返回 "failed to open stream: File name too long",但 url 从浏览器中打开正常

php - 使用外部 URL 在 Laravel 中进行功能测试(谷歌登录)

PHP 表单仅将图像发送到 MYSQL 数据库,没有其他值

MYSQL 一次查询多个表

php - MySQL ALTER TABLE 删除表