I know that this question has been asked probably a million times, but none of them have solved this problem. I am using PHP to connect to my localhost databse with the PHP script show below:
<?php
// CONNECT TO THE DATABASE
$DB_NAME = 'users';
$DB_HOST = 'localhost';
$DB_USER = '********';
$DB_PASS = '********';
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// A QUICK QUERY ON A FAKE USER TABLE
$query = "SELECT * FROM `members` WHERE `username`='$myusername' and `password`='$mypassword'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
// GOING THROUGH THE DATA
if($result->num_rows == 1) {
header("location:login_success.php");
}
else {
header("location:fail.php");
}
// CLOSE CONNECTION
mysqli_close($mysqli);
?>
This is able to connect to the database, but it is unable to find the database 'users'. You can see from the image listed below, that the database exists, but it can't find it.
https://i.stack.imgur.com/A5uuL.png
Any help that will resolve this would be greatly appreciated!