-2

I want to make the system login. After user insert username and password, he/she is redirect to index.php But, i got a problem for the process script.

Notice: Undefined variable: conn in C:\xampp\htdocs\file\login.php on line 15

Fatal error: Call to a member function query() on null in C:\xampp\htdocs\file\login.php on line 15

And here is the script:

<?php
include('connection.php');
session_start();

if ( ! empty($_SESSION['username'] ) ) {
    header('Location:index.html?');
    exit;
}

if(isset($_POST["login"]))           //FUNGSI LOGIN
{ 
    $username   = $_POST["username"];
    $password   = $_POST["password"];

    $sql_login      = "SELECT * FROM tbl_user WHERE username='$username' AND password='$password'";
    $result_login   = $conn->query($sql_login);
    $row_login      = $result_login->fetch_assoc();
    $numrow_login   = $result_login->num_rows;

    if($numrow_login==1)
    {
        $_SESSION['username'] = $username;
        header('Location:index.html?');
        exit;
    }
}
?>

1 Answers1

-1

Fatal error: Call to a member function query() on null in C:\xampp\htdocs\puskesmas\login.php on line 15 This line gives you the idea the $conn is not defined

Try $conn = new connection()

CooLmAn
  • 17
  • 5