I have a mysql query like following
mysql_query("select * from user where name='$name' LIMIT 1");
If suppose my input from client side is ‘John’ there will be MySQL error in my query.
What is the best practice of preventing this?
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.
At first, mysql_* functions are deprecated and you should use PDO or mysqli_ instead. This two libraries implements prepared Statements which automatically escape your input.
If you want to use mysql_* instead, you have to call
mysql_real_escape_stringto the passed var