Question
I am getting errors, Notice : Undefined variable: db in C:xampphtdocsCheckLogin.php Warning : mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:xampphtdocsCheckLogin.php Notice
I am getting errors,
Notice: Undefined variable: db in C:\xampp\htdocs\CheckLogin.php Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\CheckLogin.php Notice: Undefined variable: db in C:\xampp\htdocs\CheckLogin.php Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\CheckLogin.php
I have a table created already for users, with id, username, password,.
//sql connection variables
$db_host = "****"; // im using a server to host my files i have replaced my info with stars, you can use localhost if u want
$db_username = "*****"; // Database username
$db_password = "*****"; // Database password
$db_data = "******"; // Database here
$db_connection = mysqli_connect ("$db_host", "$db_username", "$db_password", "$db_data")
or die ('I cannot connect to the database. ');
?>
---------------------------------------------------
CheckLogin.php
require_once('db.php');
session_start();
// Login user if (isset($_POST['login'])) { $username = mysqli_real_escape_string($db, $_POST['username']); // eror in this line $password = mysqli_real_escape_string($db, $_POST['password']); // error in this line if (empty($username)) { array_push($errors, "Username is required"); } if (empty($password)) { array_push($errors, "Password is required"); } if (count($errors) == 0) { $password = md5($password); $query = "SELECT * FROM users WHERE username='$username' AND password='$password'"; $results = mysqli_query($db, $query); if (mysqli_num_rows($results) == 1) { $_SESSION['username'] = $username; $_SESSION['success'] = "You are now logged in"; header('location: default.html'); // direct to home page }else { array_push($errors, "Wrong username/password combination"); } echo(" "); print_r($errors); }
}
?>
---------------------------------
LoginPage.php
Log In
Login Form
Username:
Password:
Remember me
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started