我有一个 mysql 查询,我正在将其转换为 mysqli(准备好的语句),但我遇到了一个引发以下错误的问题,
警告:mysqli_stmt::bind_result():绑定变量的数量与准备好的语句中的字段数量不匹配
mysql代码
$random_name_generated = vpb_generate_random_name().'.jpg'; //Generated name for uploaded files or images
if (move_uploaded_file($_FILES['file_to_upload']['tmp_name'], $final_uploads_location)) {
$check_empty_field = mysql_query("select * from `vpb_uploads` where `username` = '".mysql_real_escape_string(strip_tags($username))."' and `firstname` = '".mysql_real_escape_string("")."' and `lastname` = '".mysql_real_escape_string("")."'");
if (mysql_num_rows($check_empty_field) < 1) {
mysql_query("insert into `vpb_uploads` values('', '".mysql_real_escape_string($username)."', '', '', '".mysql_real_escape_string($random_name_generated)."', '', '', '', '', '".mysql_real_escape_string(date("d-m-Y"))."')");
$identity = "image_one";
} else {
$get_empty_field = mysql_fetch_array($check_empty_field);
$image_one = strip_tags($get_empty_field["image_one"]);
$image_two = strip_tags($get_empty_field["image_two"]);
$image_three = strip_tags($get_empty_field["image_three"]);
$image_four = strip_tags($get_empty_field["image_four"]);
$image_five = strip_tags($get_empty_field["image_five"]);
global $identity;
以下是我尝试过的,即使它不起作用。我已经知道它不会起作用,但我想在问问题之前自己尝试一下。错误来自$get_empty_field = $stmt->bind_result($stmt);
if (move_uploaded_file($_FILES['file_to_upload']['tmp_name'], $final_uploads_location)) {
$firstname = '""';
$lastname = '""';
$stmt = $mysqli->prepare("select * from `vpb_uploads` where `username` = ? and `firstname` = ? and `lastname` = ?");
$stmt->bind_param('sss', $username, $firstname, $lastname);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows < 1) {
$date = 'date("d-m-Y")';
$image_2 = "''";
$image_3 = "''";
$image_4 = "''";
$image_5 = "''";
$stmt = $mysqli->prepare("insert into `vpb_uploads` (`username`, `firstname`, `lastname`, `image_one`, `image_two`, `image_three`, `image_four`, `image_five`, `date`) values(?,?,?,?,?,?,?,?,?)");
$stmt->bind_param('sssssssss', $username, $firstname, $lastname, $random_name_generated, $image_2, $image_3, $image_4, $image_5, $date);
$stmt->execute();
$stmt->close();
$identity = "image_one";
} else {
$get_empty_field = $stmt->bind_result($stmt);
$image_one = strip_tags($get_empty_field["image_one"]);
$image_two = strip_tags($get_empty_field["image_two"]);
$image_three = strip_tags($get_empty_field["image_three"]);
$image_four = strip_tags($get_empty_field["image_four"]);
$image_five = strip_tags($get_empty_field["image_five"]);
global $identity;