I have a form where a user can type in the firstname to search, my query is not returning the correct results, what am I doing wrong?
$sfn = $_POST["Text1"];
$sql = "SELECT * FROM ex_usrs WHERE firstname LIKE '$sfn'";
...
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your query will only return rows where
firstnameis equal to$_POST["Text1"]. When you useLIKEyou can use a wildcard (%) to represent any number of characters.This will find rows where
firstnamestarts with$_POST["Text1"].This will find rows where
firstnameends with$_POST["Text1"].This will find rows where
firstnamecontains$_POST["Text1"].Note: Never use variables from
$_POSTwithout escaping them first. What if I searched for"O'Neil"(or worse"'; DROP TABLE ex_users; -- ")?