Tips and Tricks on Web and Technology

Sanitize User Input with MySQL

Never believe your user would always provide you with the correct or expected input. People can play around with your security and mess up with the important data. You might end up losing your customers or their data (emails or passwords) or may be your website.

Always protect your code and database from hacks and intrusions by sanitizing the user inputs.

How to sanitize user input?

1) Put a size limit on every input field.

substr($_POST['name'], 0, 50);

2) Check whether input’s context is per expected or not, i.e., where you are expecting an integer do not entertain alphabets or others.