I was wondering how to rewrite/fix the following code.
Basically, I have a database named DB and a table in it called poems. I want to get all the data in the poems table that has a certain ID (i.e. who wrote the poem, the tags it has, its content, when it was created, etc.) and securely store it in an array to later be printed out onto a web page.
The hosting service I have doesn't have support for the mysqlnd driver needed for mysqli_getresult(), so I currently get the error "Call to undefined method mysqli_stmt::get_result()"
$mysqli is a pre-written connection to the database, using new mysqli()
function getpoemdata($mysqli) {
echo "Function started.";
if(isset($_GET['poem_id'])) { // Check if poem_id is set in the URL
$poemid=$_GET['poem_id']; // Get poem_id set in URL
if (!is_int($poemid)) { $poemid = 7; } // Check if poem_id is set an integer
if ($poemid <= 0) { $poemid = 7; } //Check if poem_id is positive- If negative, it is changed to positive
$stmt = $mysqli->prepare("SELECT * FROM `poems` WHERE `poem_id` = ?");
$stmt->bind_param('i', $poemid);
$stmt->execute();
$result = $stmt->get_result();
$returned_data = $returned_data->fetch_array();
while($stmt->fetch()){
echo $returned_data . '<br />';
}
$stmt->free_result();
}
else { //If user simply types "poemview.php" and not "poemview.php?poem_id="
echo "error";
}
}
Thank you a ton in advance for any help- I'm pretty new to PHP and trying to learn it as I go along- it's just a little overwhelming everytime I try to do something new and need to learn a dozen more functions.