so i am making my first website and im trying to connect to my mysql databaste running on apache server via xaamp
My code is below and the errors it is giving when i try to login, a screenshot of the database is also attached
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$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_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: index.html");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
config.php:
define('DB_SERVER', '127.0.0.1');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'rootpassword');
define('DB_DATABASE', 'database');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in D:\xampp\htdocs\Website\Websiteassesment\config.php on line 6
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, bool given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 8
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, bool given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 9
Warning: mysqli_query() expects parameter 1 to be mysqli, bool given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 12
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 13
Notice: Trying to access array offset on value of type null in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 14
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\Website\Websiteassesment\loginform.php on line 16
any help would be appreciated