Organizational Research By

Surprising Reserch Topic

what does the mysqli error expects parameter 1 to be mysqli null given mean


what does the mysqli error expects parameter 1 to be mysqli null given mean  using -'php,mysql,mysqli'

I have this PHP page:

<?php

//$_GET['invite'] = kNdqyJTjcf;

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

$q = "SELECT invite_id FROM signups_invited WHERE (code = '$code') LIMIT 1";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

if (mysqli_num_rows($r) == 1) {
    echo 'Verified';
} else {
    echo 'That is not valid. Sorry.';
}

?>


This is returning the error Warning: mysqli_error() expects parameter 1 to be mysqli, null given.

Any idea why?
    

asked Oct 13, 2015 by amit.gupta
0 votes
2 views



Related Hot Questions

3 Answers

0 votes

You need to define: $dbc before

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

ex:

$dbc = mysqli_connect("localhost", "my_user", "my_password", "world");
answered Oct 13, 2015 by sachin wagh
0 votes

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. :)

answered Oct 13, 2015 by gauravg.gwl
0 votes

Hi please don't confuse with mysql_connect(); with mysqli_connect();

Try to change as follows

$conn=mysqli_connect("yourhost", "username", "password", "database-name") or die("initial host/db connection problem");`

Then if its connected then pass your query with

mysqli_querry($conn, "your query string") or die ("query not executed");`

Now it works fine!

answered Oct 13, 2015 by ashish singh

...