Skip to content
Advertisement

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

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: $qn<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?

Advertisement

Answer

You need to define: $dbc before

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

ex:

$dbc = mysqli_connect("localhost", "my_user", "my_password", "world");
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement