Warning: mysqli_error () expects exactly 1 parameter, 0 given error

I follow the tutorial, but the author of the textbook does not answer the questions - but here is my request

I get the following error. Warning: mysqli_error () expects exactly 1 parameter, 0 is set, the problem in this line of code is

$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 

Whole code

 session_start(); require_once "scripts/connect_to_mysql2.php"; //Build Main Navigation menu and gather page data here $sqlCommand = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC"; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); $menuDisplay = ''; while ($row = mysqli_fetch_array($query)) { $pid = $row["id"]; $linklabel = $row["linklabel"]; $menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />'; } mysqli_free_result($query); 

The input file has the following line

 $myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") or die ("could not connect to mysql"); with reference to $myConnection, why do I get this error? 

thanks

+8
php mysql mysqli
source share
3 answers

mysqli_error () you need to pass the database connection as a parameter. The documentation contains some useful examples:

http://php.net/manual/en/mysqli.error.php

Try changing your problematic line like this and you should be in good shape:

 $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); 
+21
source share

mysqli_error function requires $myConnection as parameters, so you get a warning

+4
source share

Firstly, the problem is that you did not specify any parameter for mysqli_error. I see that it was resolved based on a post here. Most likely, the following problem occurs due to the wrong file path for the included file.

Are you sure this code

 $myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") or die ("could not connect to mysql"); 

is in the scripts folder, and your main code file is at the same level as the script folder?

+1
source share

All Articles