0

Hello whenever i press the signin button onmy website i get this error:

Notice: Undefined index: active in C:\xampp\htdocs\repute-multipurpose-theme-v1.3\theme\login.php on line 14

I was wondering if you guys know how to fix it. I keep reading about an isset function, but i tried that on line 14 and it gave another error so it didn't seem to work.

<?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";
      }
   }
?>
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • Flagged as typo. Just add `active` column to your query and then use prepared statements to prevent sql injection – Rotimi Mar 18 '18 at 18:23

2 Answers2

0

$row['active'] should be $row[0]['active']; And also you need to define the active column in your query

Sagar Jajoriya
  • 2,377
  • 1
  • 9
  • 17
0

You haven't selected active column in your query. You just have customer_id:

$sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";

Also, you are prone for SQL Injection.


In case, you are not aware of Undefined Index error.

Thamilhan
  • 13,040
  • 5
  • 37
  • 59