I have this query:
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
I ceated two variables and a loop to do the binding:
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.=', ';
}
}
When I print out the two arrays $sss
and $fieldNameValues
I get this:
s ,s ,s ,s ,s ,s ,s ,s ,s ,s ,s ,s
p2iic, fred, fred, fred, fred, fred, fred, fred, fred, fred, fred, fred
Which looks right to me.
However when prepare and bind thus:
$record= $conn->prepare($qry);
$record-> bind_param($sss, $fieldNameValues);
I get errors telling me
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
which as far as I can see it does - there are 12 in the $ary, and twelve in $sss and 12 in $fieldNamesValues
What's wrong please?