Php mysqli bind_param类型中的元素数不';不匹配绑定变量
我有一个疑问:Php mysqli bind_param类型中的元素数不';不匹配绑定变量,php,mysqli,Php,Mysqli,我有一个疑问: qry=INSERT INTO assessments (Speaking_and_listening, Reading, Writing, Number, Measure, Geometry, Statistics, Science, ICT, Health_and_well_being, Relationships, Living_in_the_wider_world ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 我添加了两个变
qry=INSERT INTO assessments (Speaking_and_listening, Reading, Writing, Number, Measure, Geometry, Statistics, Science, ICT, Health_and_well_being, Relationships, Living_in_the_wider_world ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
我添加了两个变量和一个循环来进行绑定:
foreach ($subjectListArray as $key=>$subject){
$sss .='s';
if (!isset($_POST[str_replace(" ","_",$subject)])){
$fieldNameValues.='fred';
}else{
$fieldNameValues.=$_POST[str_replace(" ","_",$subject)];
}
if ($key!=(count($subjectListArray)-1)){
$sss.=' ,';
$fieldNameValues.=', ';
}
}
当我打印出两个数组$sss
和$fieldNameValues
时,我得到以下结果:
s ,s ,s ,s ,s ,s ,s ,s ,s ,s ,s ,s
p2iic, fred, fred, fred, fred, fred, fred, fred, fred, fred, fred, fred
在我看来这是正确的
但是,当准备并绑定时:
$record= $conn->prepare($qry);
$record-> bind_param($sss, $fieldNameValues);
我告诉我有错误
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
据我所知,在$ary中有12个,在$sss中有12个,在$FieldNames中有12个
有什么问题吗?请删除逗号。它应该是
$sss=“ssssss”代码>。哦,我还认为不能将该字符串用于多个参数。应该是bind_param($sss,$param1,$param2,$param3)
等等。关于逗号!!!让它工作了Tanuel-所以谢谢,但它涉及硬编码,必须有更好的方法来做。你正在寻找。还要看一下删除逗号。它应该是$sss=“ssssss”代码>。哦,我还认为不能将该字符串用于多个参数。应该是bind_param($sss,$param1,$param2,$param3)
等等。关于逗号!!!让它工作了Tanuel-所以谢谢,但它涉及硬编码,必须有更好的方法来做。你正在寻找。也来看看