小编典典

mysqli_error()期望参数1为mysqli,给定为null表示什么?

mysql

我有这个PHP页面:

<?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.';
}

?>

这将返回错误Warning: mysqli_error() expects parameter 1 to be mysqli, null given

知道为什么吗?


阅读 246

收藏
2020-05-17

共1个答案

小编典典

您需要定义:$dbc之前

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

例如:

$dbc = mysqli_connect("localhost", "my_user", "my_password", "world");
2020-05-17