What does the mysqli_error() expects parameter 1 to be mysqli, null given mean?

You need to define: $dbc before

 $code = mysqli_real_escape_string ($dbc, $_GET['invite']);

ex:

$dbc = mysqli_connect("localhost", "my_user", "my_password", "world");

Book of Zeus already gave you the answer. This is for your future reference (and hopefully to help others in the future).

It's helpful to learn to read error messages and try to figure out what might be causing them. :)

This one tells you exactly what the problem is, and where to start looking.

Warning: mysqli_error() expects parameter 1 to be mysqli, null given.

The message tells you that the problem is parameter 1 provided to mysqli_error, and that it was null when mysqli_error expected it to be a mysqli.

So look at the first parameter you're providing to mysqli_error, and you'll see it's $dbc. You know now that the problem is that $dbc is null when the call to mysqli_error() is made. So look at how it is that $dbc can be null. Oh, right - you didn't declare it and assign anything to it, because the first place it's used in the code is here:

$code = mysqli_real_escape_string ($dbc, $_GET['invite']);

and it's being used as if it's already something other than null. Since this is at the start of your code, the problem is that you forgot to declare and initialize it by connecting to the database. Problem solved. :)


undefined variable $dbc in mysqli_error($dbc). you need to put your connection obj here.

Tags:

Mysql

Php

Mysqli