I am trying to do a search on my database where it returns results based on exact surnames and first names with the initial of the name entered in an input box. For instance, if the user enters Simon Burns
it will return all users with the initial S
for the first name and Burns
for the Surname. Here is my code.
Sorry if this has been covered before but I cannot find a simple answer that works.
$firstname = filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING);
$surname = filter_input(INPUT_POST, 'surname', FILTER_SANITIZE_STRING);
$prep_query = "SELECT id, firstname, surname, profilepic, Gender, StartYear, EndYear, CircaStart, CircaEnd, JnrHouse, SnrHouse
FROM people WHERE firstname LIKE ? AND surname = ?";
$namecheckresult = $connection->prepare($prep_query);
// Return all matches wether registered on not
if ($namecheckresult)
{
$initial = $firstname[0];
$namecheckresult->bind_param( 'ss', $initial . '%', $surname);
$namecheckresult->execute();
$namecheckresult->store_result();
$namecheckresult->bind_result($id, $first, $last, $ProfilePic, $Gender, $StartYear, $EndYear, $CircaStart, $CircaEnd, $JnrHouse, $SnrHouse);