I am having some trouble getting MySQLi to connect and respond properly. It should be relaying a connection error any time it is unable to connect to the database, but it doesn't, even when enter invalid details in an attempt to force a connection error.
$emailaddress = $_POST['emailaddress'];
$password = $_POST['password'];
if ($emailaddress&&$password)
{
$db = new mysqli('loalhost','rot','','FitessHouse');
if($db->connect_errno > 0)
{
die('Unable to connect to database [' . $db->connect_error . ']');
}
}
EDIT: Let me be more clear. I am trying to get MySQLi to return a connection error because the connection fails. I'm not trying to fix the connection. When I hit "Submit" it takes me to a blank page, which means my die statement is not working.
Fixed it and now have this error:
Notice: Undefined index: emailaddress in /Applications/XAMPP/xamppfiles/htdocs/FitnessHouse/login.php on line 5
This line of code should display the error and stop the script:
$db = new mysqli('loalhost','rot','','FitessHouse')
or die('Unable to connect to database [' . $db->connect_error . ']');
You can also use trigger_error instead of die:
$db = new mysqli('loalhost','rot','','FitessHouse');
if($db->connect_errno)
trigger_error('Unable to connect to database [' . $db->connect_error . ']', E_USER_ERROR);