Jump to content

Blank Page


JohnJ

Recommended Posts

I am attempting to set up a connection to a database via MySQLi. I recently entered invalid details to check whether or not the error reporting would work correctly; it didn't. It's simply showing me a blank page when I click "Sign In."

<?php


ini_set('display_errors', 1); error_reporting(~0);


$emailaddress = $_POST['emailaddress'];
$password = $_POST['password'];


if ($emailaddress&&$password)


{


$db = @new mysqli('loalhost','rot','','FitessHouse');


if($db->connect_errno) 


{
trigger_error('Unable to connect to database [' . $db->connect_error . ']', E_USER_ERROR);


}


}


?>

 

Link to comment
Share on other sites

You would only get an error if both of the conditions were true. You can add some debugging lines to see which conditions are true/false.

 

Try this and see what is returned:

 

echo "DEBUG: check if $emailaddress or $password are false<br>\n";
if ($emailaddress && $password)
{
    echo "DEBUG: $emailaddress and $password are not false<br>\n";
    $db = @new mysqli('loalhost','rot','','FitessHouse');
    if($db->connect_errno)
    {
        trigger_error('Unable to connect to database [' . $db->connect_error . ']', E_USER_ERROR);
    }
    else
    {
        echo "DEBUG: DB connection completed<br>\n";
    }
}
Edited by Psycho
Link to comment
Share on other sites

Would it be easier (or possible) to create a file dedicated to connecting to the database whenever needed? So that instead of coding this time and time again, I could just have it reference a MySQL connection file? Or is that possible?

Link to comment
Share on other sites

Yes, that is the preferred way to do it. I typically create an application such that any page call will load a "bootstrap" file which will perform any common tasks. I would still have separate files for DB connection and other tasks, and then include those in the boostrap file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.