I have a function that is supposed to give me a staff members name from his ID number so my php is like this
$staffId = $_GET['staff_id'];
$staff = staff_load($staffId);
and my function is like this
function staff_load()
{
$dbh = dbh_get(); //connects to database
$sql = 'select user_name from user_staff where user_id = ?';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$staff = $stmt->fetch();
dbh_free($dbh); //disconnects from database
return $staff;
}
But when I try and use the $staff variable, it shows nothing. I can't work out what I'm doing wrong. I've tried a bunch of variants and gotten nowhere except frustrated.
<td>Book for ' . $staff . '</td>
function staff_load()) needs to accept the value passed to it (function staff_load($id)), and bind it in the SQL queryfunction staff_load()takes no parameter, it should befunction staff_load($id)and then inside yourexecute()addexecute([$id])->prepare()a query, but you dont bind the parameter to it<?php error_reporting(E_ALL); ini_set('display_errors', 1);to see if it yields anything.