-2

I have written a mysql_query and it is not working.

I want to know the problem via mysqli_error() however it gives the following error mysqli_error() expects parameter 1 to be mysqli

my mysql code is as follows:

$connect = mysqli_connect("localhost","root", "", "tomuman");
$query = mysqli_query($connect, "SELECT id, to FROM messages WHERE read='0'");

and mysqli_error as follows:

echo mysqli_error($query);

What could cause this problem?

Dediqated
  • 901
  • 15
  • 35

2 Answers2

2

You should not use $query as a parameter for mysqli_error()

use

echo mysqli_error($connect);

Just after trying to connect you can also check for specific connection errors with:

if (mysqli_connect_errno()) {
  echo mysqli_connect_error();
  exit();
}
Sven Tore
  • 967
  • 6
  • 29
-1

Add following code in your query to get the mysql error message.

or die (mysqli_error($connect))

as like below

$query = mysqli_query($connect, "SELECT id, to FROM messages WHERE read='0'") or die (mysqli_error($connect));


     if ($query) {
        echo "success";
     }
     else {
          echo("Error description: " . mysqli_error($connect));
     }
Ahmad Sharif
  • 4,141
  • 5
  • 37
  • 49