Php 绑定结果失败

Php 绑定结果失败,php,mysqli,prepared-statement,Php,Mysqli,Prepared Statement,实际上我试过mysqli->fetch_array()用于获取数组,但无法工作,因此我使用了bind_result();它抛出下面的错误 警告:mysqli_stmt::bind_result():bind变量的数量与prepared语句中的字段数量不匹配 所以我对bind_result做了一个错误检查,结果是bind_result()失败:那么我到底做错了什么 $wtf = ""; $hello = ""; $check_empty_field = $mysqli - > prepare

实际上我试过
mysqli->fetch_array()用于获取数组,但无法工作,因此我使用了bind_result();它抛出下面的错误

警告:mysqli_stmt::bind_result():bind变量的数量与prepared语句中的字段数量不匹配

所以我对bind_result做了一个错误检查,结果是
bind_result()失败:
那么我到底做错了什么

$wtf = "";
$hello = "";
$check_empty_field = $mysqli - > prepare("select `username`, `firstname`, `lastname` from `vpb_uploads` where `username` = ?  and `firstname` = ? and `lastname` = ?");
$check_empty_field - > bind_param('sss', $username, $wtf, $hello);
$check_empty_field - > execute();
$check_empty_field - > store_result();
if($check_empty_field - > num_rows < 1) {
  $date = date("d-m-Y");
  $i2 = '';
  $i3 = '';
  $i4 = '';
  $i5 = '';
  $insert = $mysqli - > prepare("insert into `vpb_uploads` (`username`, `firstname`, `lastname`, image_one, image_two, image_three, image_four, image_five, date)values(?,?,?,?,?,?,?,?,?)");
  $insert - > bind_param('sssssssss', $username, $wtf, $hello, $random_name_generated, $i2, $i3, $i4, $i5, $date);
  $insert - > execute();
  $identity = "image_one";
} else {
  $get_empty_field = $check_empty_field - > bind_result($username, $wtf, $hello);
  if(false === $get_empty_field) {
    die('bind_result() failed: '.htmlspecialchars($mysqli - > error));
  }
  $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;
}
$wtf=”“;
$hello=”“;
$check\u empty\u field=$mysqli->prepare(“从`vpb\u uploads`中选择`username`、`firstname`、`lastname`,其中`username`=?和`firstname`=?”;
$check_empty_field->bind_param('sss',$username,$wtf,$hello);
$check_empty_field->execute();
$check_empty_field->store_result();
如果($check\u empty\u field->num\u rows<1){
$date=日期(“d-m-Y”);
$i2='';
$i3='';
$i4='';
$i5='';
$insert=$mysqli->prepare(“插入到'vpb_上传'('username','firstname','lastname',image_一,image_二,image_三,image_四,image_五,date)值(?,,,,,,,,,,?);
$insert->bind_参数('sss'、$username、$wtf、$hello、$random_name_-generated、$i2、$i3、$i4、$i5、$date);
$insert->execute();
$identity=“image\u one”;
}否则{
$get\u empty\u field=$check\u empty\u field->bind\u result($username,$wtf,$hello);
if(false==$get\u空\u字段){
die('bind_result()失败:'.htmlspecialchars($mysqli->error));
}
$image_one=带标签($get_empty_field[“image_one”]);
$image\u two=带标签($get\u empty\u field[“image\u two”]);
$image\u three=带标签($get\u empty\u field[“image\u three”]);
$image\u four=带标签($get\u empty\u field[“image\u four”]);
$image_five=带标签($get_empty_field[“image_five”]);
全球美元身份;
}

引发此错误是因为您没有将SQL查询返回的每个列名都设置为变量

例如:

如果您的表中有6列,并且选择了all(*),则您必须:

$stmt->bind_result($Col_1,$Col_2,$Col_3,$Col_4,$Col_5,$Col_6);
如果您有:

$stmt->bind_result($Col_1,$Col_2,$Col_3,$Col_4,$Col_5);
将抛出一个错误



您没有包括所有相关代码,在哪里初始化了
$stmt
->
真的可以处理这些额外的空格吗?@因此,很抱歉,这是打字错误。还有,
$username
是否定义了?(尽管我认为这不是问题所在)@从这里是的,它被定义错误消失了,但是查询将所有图像插入到一个列中,而不是将每个图像插入到一个新列中,然后您必须回显您插入的变量,确保它们填充正确您知道我将$check\u empty\u field和$get\u empty\u field query更改为mysql,并且可以正常工作好的插入查询没有问题。问题在于这两个问题
$check_empty_field->data_seek(0);
  $get_empty_field = $check_empty_field - > bind_result($username, $wtf, $hello);