JohnJ Posted May 9, 2013 Share Posted May 9, 2013 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); } } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 9, 2013 Share Posted May 9, 2013 (edited) 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 May 9, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
JohnJ Posted May 9, 2013 Author Share Posted May 9, 2013 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 9, 2013 Share Posted May 9, 2013 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 9, 2013 Share Posted May 9, 2013 (edited) Try error_reporting(-1) instead of error_reporting(-0) Edited May 9, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.