I am pretty new to using php and I am currently working on a site that has an interactive animal glossary.
I have been editing php pages written by another developer and I have come across an error when I run the bind_param() function.
Here is the meat of the page, a good deal has been removed so that I only expose my error.
if (isset($_GET['id'])) {
$results = array();
$stmt = $db_conn->prepare("SELECT specific.id, specific.name, specific.description, specific.group_id, m.id specific_media_id, m.type specific_media_type, m.url specific_media_url FROM ANIMAL_SPECIFIC specific LEFT JOIN MEDIA m on m.id = specific.media_id WHERE GROUP_ID = ?");
$stmt->bind_param('i', $_GET['id']);
$stmt->execute();
$stmt->bind_result($specific_id, $name, $description, $group_id, $specific_media_id, $specific_media_type, $specific_media_url);
while ($stmt->fetch()) {
$specific = array(
"id" => $specific_id,
"name" => $name,
"description" => $description,
"group_id" => $group_id
);
if (!empty($specific_media_id)) {
$media = array(
"id" => $specific_media_id,
"type" => $specific_media_type,
"url" => $specific_media_url
);
$specific["media"] = $media;
}
$results["results"]["animal_specific"][] = $specific;
}
$stmt->close();
echo json_encode($results);
}
}
The error I get is: Fatal error: Call to a member function bind_param() on a non-object in /web/animaldetailsJSON.php on line 13 Call Stack: 0.0058 647448 1. {main}() /web/animaldetailsJSON.php:0
I am sure there is some small error that I am overlooking. All I need is a JSON of all SPECIFIC_ANIMALS with a certain group_id