Firstly, I know that this is a repeating question and I'm asking the same question. But I have read all the solution provided that linked to the same problem, but when I followed the suggested solution, it will trigger more warnings to appear. This is what I have in my code
if($stmt = $mysqli->prepare("SELECT * FROM emergency WHERE id=?"))
{
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($id, $patient_seen_u, $patient_seen_a);
$stmt->fetch();
// show the form
renderForm($patient_seen_u, $patient_seen_a, NULL, $id);
$stmt->close();
to get the
Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:\xampp\htdocs\gsd\emergency\records.php on line 122
so I change the codes into
if($stmt = $mysqli->prepare("SELECT date, patient_seen_u, patient_seen_a FROM emergency WHERE id ='?'"))
{
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($id, $date, $patient_seen_u, $patient_seen_a);
$stmt->fetch();
// show the form
renderForm($date, $patient_seen_u, $patient_seen_a ,NULL, $id);
$stmt->close();
}
only to get these warning;
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in C:\xampp\htdocs\gsd\emergency\records.php on line 119
Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:\xampp\htdocs\gsd\emergency\records.php on line 122
and also try to do this;
if($stmt = $mysqli->prepare("SELECT `date`, `patient_seen_u`,`patient_seen_a` FROM `emergency` WHERE `id` = '?'"))
{
$stmt->bind_param("iii", $id);
$stmt->execute();
$stmt->bind_result($id, $date, $patient_seen_u, $patient_seen_a);
$stmt->fetch();
// show the form
renderForm($date, $patient_seen_u, $patient_seen_a ,NULL, $id);
$stmt->close();
}
but the code is not working either. How can I solve this?
Remove the quotes surrounding the placeholder and also add the id column to match the arrangement order for bind_result
if($stmt = $mysqli->prepare("SELECT id, date, patient_seen_u, patient_seen_a FROM emergency WHERE id =?")) {
$stmt->bind_param("i", $id);// bind as integer
$stmt->bind_result($id, $date, $patient_seen_u, $patient_seen_a);