-1

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

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Duplicate of [Nothing is seen. The page is empty and white.](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851) – Your Common Sense May 09 '13 at 14:31
  • Please paste the relevant code from pastebin to your question. – Kermit May 09 '13 at 14:33
  • *> it takes me to a blank page, which means my die statement is not working.* Actually it means only that you see a blank page. And there could be 1000 reasons for that To be sure that your die statement is not working, you have to add an else condition, to prove that. though I am sure it won't be run too – Your Common Sense May 09 '13 at 14:28

1 Answers1

0

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);
Jocelyn
  • 11,209
  • 10
  • 43
  • 60