Im trying to run a simple search query to on all the fields in my contacts table. Basically want to look in all the fields in the contacts table for any match record that is passed in $valueToSearch. My code is below I'm getting error message -Im trying to run a simple search query to on all the fields in my contacts table. Is there a problem with the structure in my sql query ? Im new to PHP
$query = "SELECT `firstName`, `lastName`, `nickName`, `cellNumber` , `workNumber` , `homeNumber` , `birthday` , `memo` FROM contacts LIKE '%".$valueToSearch."%' WHERE userId = '{$_SESSION['user_id']}' ";
You can't put LIKE before WHERE clause and LIKE need to be placed after a column. Try this way:
$query = "SELECT `firstName`, `lastName`, `nickName`, `cellNumber` , `workNumber` , `homeNumber` , `birthday` , `memo` FROM contacts WHERE userId = '{$_SESSION['user_id']}' AND `fieldYouWantToFilter` LIKE '%".$valueToSearch."%' ";