SQL injection is a typical code injection attack that exploits weaknesses of application in the database layer. SQL injection vulnerability is created when one scripting or programming language is embedded in or used as input in another with failure to verify the legality or filter for potential dangerous codes.
SQL injections are possible when input from user is either incorrectly filtered for string literals embedded in SQL query statements or itâ€™s not strongly typed thereby incurring unexpected execution.
The solution to this is to never trust user input data by default, especially those that will be used in a SQL statement. Check for data type and escape string literals before committing them into a query.