How to prevent an SQL injection in PHP?

How do you prevent sql-injection in a php application accepting user input strings?

  • Answer:

    There is only one key to prevent SQL-injection attacks - validate your user inputs. Check to see if there are any characters that may exploit the SQL syntax e.g. 1. ' (single quote) - you should add another single quote so that it becomes an escape sequence 2. -- (consequtive dashes, it indicates that the forthcoming characters are comment) - you should again use escape sequences. For a detailed description on escape sequences, consult the documentation of the DBMS that you are using

Joop L at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

There is only one key to prevent SQL-injection attacks - validate your user inputs. Check to see if there are any characters that may exploit the SQL syntax e.g. 1. ' (single quote) - you should add another single quote so that it becomes an escape sequence 2. -- (consequtive dashes, it indicates that the forthcoming characters are comment) - you should again use escape sequences. For a detailed description on escape sequences, consult the documentation of the DBMS that you are using

Deobrat

You need to find yourself a copy of the ACM Queue magazine for December 2005. Volume 3, No.10. There is a solution and description on page 13/14.

Martin

Be sure u have "register_globals = OFF" in php.ini

B1t Hunt3r

You need to find yourself a copy of the ACM Queue magazine for December 2005. Volume 3, No.10. There is a solution and description on page 13/14.

Martin

Be sure u have "register_globals = OFF" in php.ini

B1t Hunt3r

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.