mysqli_error() 期望参数 1 为 mysqli,null 是什么意思?

2021-12-25 00:00:00 php mysqli

我有这个 PHP 页面:

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
<br />MySQL Error: " . mysqli_error($dbc));

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

?>

这将返回错误警告:mysqli_error() 期望参数 1 为 mysqli,给出空值.

知道为什么吗?

推荐答案

需要定义:$dbc之前

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

例如:

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

相关文章