微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – mysqli bind_param和受影响的行错误

我是mysqli的新手,我查过过PHP手册等等,没什么用.我不太确定出了什么问题.我一直收到这个错误

Warning: MysqLi_stmt::bind_param() [MysqLi-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in C:\xampp\htdocs\new1\template.PHP on line 165

还有这个

Warning: MysqLi_stmt_affected_rows() [function.MysqLi-stmt-affected-rows]: Couldn't fetch MysqLi_stmt in C:\xampp\htdocs\new1\template.PHP on line 190

编码

$query = "INSERT INTO pets (name, age, gender, dob, breed_type, breed1, breed2, color, spay, size, hair_length, vaccine, vaccinated, dewormed, adoption_fees, aboutpet, petpic1, petpic2, petpic3) VALUES ('?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?')";

// PREPARE QUERY TO BE EXECUTED.
$stmt = $MysqLi->prepare($query);

$stmt->bind_param("sssssssssssssssssss",$petname, $petage, $petgender, $petdob, $petbreedtype, $petbreed1, $petbreed2, $petcolor, $petspay, $petsize, $pethair, $petvaccine, $petvaccineamount, $petdewormed, $petadoptfees, $aboutpet, $target_path, $target_path1, $target_path2 );

$petname  = $_POST['petname'];
$petage   = $_POST['petage'];
$petgender = $_POST['petgender'];
$petdob = $_POST['petdob'];
$petbreedtype = $_POST['petbreedtype'];
$petbreed1 = $_POST['petbreed1'];
$petbreed2 = $_POST['petbreed2'];
$petcolor = $_POST['petcolor'];
$petspay = $_POST['petspay'];
$petsize = $_POST['petsize'];
$pethair = $_POST['pethair'];
$petvaccine = $_POST['petvaccine'];
$petvaccineamount = $_POST['petvaccineamount'];
$petdewormed = $_POST['petdewormed'];
$petadoptfees = $_POST['petadoptfees'];
$aboutpet = $_POST['aboutpet'];

//EXECUTE QUERY
$stmt->execute();

//CLOSE EXECUTE
$stmt->close();

$rowcount = MysqLi_stmt_affected_rows($stmt);
if ($rowcount > 0)
{
echo "<div class='noerror'>Form has been submitted successfully!</div>";
}

请帮忙,我现在完全失去了.

解决方法:

你不能引用你的?占位符:这样做会导致它们被解析为字符串文字而不是占位符.

因此:

$query = "
  INSERT INTO pets (
    name, age, gender, dob, breed_type, breed1, breed2, color, spay, size,
    hair_length, vaccine, vaccinated, dewormed, adoption_fees, aboutpet,
    petpic1, petpic2, petpic3
  ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
";

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐