I an trying to log into my website and I get the following error,
Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\1\login.php on line 23
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\1\login.php on line 24
Warning: mysql_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\1\login.php on line 33
Here is the code for that page and the login session.
Login.php
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username = $_POST['username'];
$password = md5($_POST['password']);
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "Oliver");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("users");
// SQL qu00e020.ry to fetch information of registerd users and finds user match.
$query = mysql_query("select * from username where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if(isset($_SESSION['login_user']))
session_destroy();
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: profile.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>
Session.php
<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "Oliver");
// Selecting Database
$db = mysql_select_db("users", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select username from username where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: home.php'); // Redirecting To Home Page
}
?>
Information The database is hosted locally with database name 'users' and table 'username'. When I login i get those errors and the page just reloads.
Update
changed to
$connection = mysql_connect("localhost", "root", "Oliver") or die (mysql_error);
No i get error
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\1\login.php on line 14
Notice: Use of undefined constant mysql_error - assumed 'mysql_error' in C:\xampp\htdocs\1\login.php on line 14
mysql_error