I am struggling to find a way to get rows from a database, based on two columns, firstName and lastName according to the search bar.
The issue is on WHERE/LIKE operators and ' ".
I am using this code below:
$search = $_POST["search"];
$query = "SELECT p.id, p.lastName, p.firstName, p.jobTitle, p.email, d.name as department, l.name as location
FROM personnel p
LEFT JOIN department d ON (d.id = p.departmentID)
LEFT JOIN location l ON (l.id = d.locationID)
WHERE p.firstName LIKE '%".$search."%'
OR p.lastName LIKE '%".$search."%'";
This code it's working just for one value, for example if I remove OR p.lastName LIKE '%".$search."%'
.