Prevention of SQL injection with PHP

Source: Internet
Author: User
: This article mainly introduces PHP to prevent SQL injection. For more information about PHP tutorials, see.

SQL injection is generally caused by the inaccuracy of the syntax. The problem occurs in SQL statements, and the decisive one is quote ('). As follows:
$ SQL = "delete from table where id = '$ ID '";
Normal submission means to delete a piece of data. if the id is submitted (1 'or 1 #), the SQL statement becomes
Delete from table where id = '1' or 1 #';
In this way, the entire table will be deleted, resulting in irreparable results.
Since the problem occurs on the quote, you only need to escape it (\')

  • Php provides two functions
Addslashes ($ str) // We recommend that you use the following to avoid character set problems: mysql_real_escape_string ($ str, $ link)
// Prevent integer data from being enclosed by SQL quotation marks, and force function ($ str) {return "'" to enclose the converted data in quotation marks "'". mysql_real_escape_string ($ str, $ this-> link ). "'";}

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces the prevention of SQL injection in PHP, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.