我正在尝试在我的 PHP 项目中的数据库中的 29 个字段中进行搜索。我正在使用 mysqli 连接到我的数据库。当我不尝试使用 bind_param() 时,我的查询工作正常,但当我使用错误时失败:
PHP Warning: mysqli_stmt::bind_param() [<a href='mysqli-stmt.bind-param'>mysqli-stmt.bind-param</a>]: Number of variables doesn't match number of parameters in prepared statement in /search.php on line 6
我的代码如下:
<?php
$find = $_POST['find'];
if (strcasecmp($_POST['in'], 'users') == 0) {
$query = $db->prepare("SELECT u.id, u.group_id, u.username, u.email, m.credits, m.first_name, m.last_name, m.address1, m.address2, m.city, m.state, m.country, m.zipcode, m.about, m.account_status, m.vacation_status FROM kf_users u JOIN kf_usermeta m ON u.id = m.id WHERE u.id LIKE '%?%' OR u.group_id LIKE '%?%' OR u.ip_address LIKE '%?%' OR u.username LIKE '%?%' OR u.password LIKE '%?%' OR u.salt LIKE '%?%' OR u.email LIKE '%?%' OR u.activation_code LIKE '%?%' OR u.forgotten_password_code LIKE '%?%' OR u.remember_code LIKE '%?%' OR u.created_on LIKE '%?%' OR u.last_login LIKE '%?%' OR u.active LIKE '%?%' OR u.FUID LIKE '%?%' OR m.id LIKE '%?%' OR m.credits LIKE '%?%' OR m.rating LIKE '%?%' OR m.user_id LIKE '%?%' OR m.first_name LIKE '%?%' OR m.last_name LIKE '%?%' OR m.address1 LIKE '%?%' OR m.address2 LIKE '%?%' OR m.city LIKE '%?%' OR m.state LIKE '%?%' OR m.country LIKE '%?%' OR m.zipcode LIKE '%?%' OR m.about LIKE '%?%' OR m.account_status LIKE '%?%' OR m.vacation_status LIKE '%?%'");
$query->bind_param('sssssssssssssssssssssssssssss',$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find,$find);
$query->execute();
$query->bind_result($id, $group, $username, $email, $credits, $first_name, $last_name, $address1, $address2, $city, $state, $country, $zipcode, $about, $account_status, $vacation_status);
while ($query->fetch()) {
$result['id'] = $id;
$result['group'] = $group;
$result['username'] = $username;
$result['email'] = $email;
$result['credits'] = $credits;
$result['first_name'] = $first_name;
$result['last_name'] = $last_name;
$result['address1'] = $address1;
$result['address2'] = $address2;
$result['city'] = $city;
$result['state'] = $state;
$result['country'] = $country;
$result['zipcode'] = $zipcode;
$result['about'] = $about;
$result['account_status'] = $account_status;
$result['vacation_status'] = $vacation_status;
$output[] = $result;
}
$query->close();
}
?>
同样,如果我注释掉我的 bind_param() 行,并将?
查询中的 有人对这里可能出现的问题有任何想法吗?