MYSQL error expects parameter 1


#1

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /customers/4/1/b/sebastiansoegaard.dk/httpd.www/session.php on line 7 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /customers/4/1/b/sebastiansoegaard.dk/httpd.www/session.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at /customers/4/1/b/sebastiansoegaard.dk/httpd.www/session.php:7) in /customers/4/1/b/sebastiansoegaard.dk/httpd.www/session.php on line 14

im getting this error in plain text at the top of my welcome.php site. its where you go after logging in


#2

Did you look at the line of code being mentioned in the 1st error and attempt to find out why parameter 1 is a null value instead of the expected mysqli connection?

If your code ‘worked’ before and this suddenly started, it means that your database connection failed AND you don’t have any error handling for the database statements - connection, query, prepare, or execute. For this case, your code needs to ALWAYS have error handling for database statements. Enabling exceptions for the db extension you are using is the simplest way to do this (takes only one line of code), and then let php catch any exception, where it will use its error_reporting, display_errors, and log_errors settings to control what happens with the actual error information.

If your code never worked, you need to find out why the connection variable either doesn’t exist at all, doesn’t exist in the same scope where the mysqli_query() call is at, or it does exist but is a null value. For this case, if you cannot determine the cause of the problem, you would need to post all the relevant code (less any db connection credentials) if you want someone here to help.


#3

please post you code so that I can identify your error. You are using mysqli and syntax will as follows :
$myConnection= mysqli_connect("$db_host","$db_username","$db_pass") or die (“could not connect to mysql”);

mysqli_select_db($myConnection, “mrmagicadam”) or die (“no database”);