Click here to Skip to main content
15,886,689 members

Undefined index PHP error

Member 13723570 asked:

Open original thread
I've been trying to make a login page with 000webhost, and this error keeps popping up, and i know there are tons of these king of questions everywhere but i still cant fix it

this is the error

Notice: Undefined index: active in /storage/ssd1/326/5052326/public_html/login.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd1/326/5052326/public_html/login.php:14) in /storage/ssd1/326/5052326/public_html/login.php on line 23

and this is the code

PHP
<?php
   include("config.php");
   session_start();
   
      // username and password sent from form 
    if($_SERVER["REQUEST_METHOD"] == "POST") {
          
      $myusername = mysqli_real_escape_string($db,$_POST['username']);
      $mypassword = mysqli_real_escape_string($db,$_POST['password']); 
      
      $sql = "SELECT * FROM admin WHERE username = '$myusername' and password = '$mypassword'";
      $result = mysqli_query($db, $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: welcome.php");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
    }
?>


What I have tried:

even my teacher couldnt fix it
Tags: PHP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900