Redirect after log in to index using php [duplicate]

107
May 05, 2018, at 8:01 PM

This question already has an answer here:

  • Reference - What does this error mean in PHP? 30 answers

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;
    }
}
?>
Answer 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()

READ ALSO
Career averages for players that have played in current season

Career averages for players that have played in current season

I am trying to list the player averages over their careers but only including players that have played at least one game in 2018, but my query is just returning players that have played 'only' in 2018, rather than the career averages for all players that have played...

124
Mysql server slower on Ubuntu server than Ubuntu desktop

Mysql server slower on Ubuntu server than Ubuntu desktop

I want to test the mysql-server (57

175