How to prevent SQL attack injection in basic phpmysql _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Basic phpmysql to prevent SQL attack injection. We used MagicQuotes in the php Tutorial to determine whether it was enabled, if the strips tutorial is lashes, otherwise, use the mysql tutorial _ real_escape_string to filter out. if the MagicQuotes function is used, we use the Magic Quotes provided by the php Tutorial to determine whether it is enabled, if the strips tutorial is lashes, use mysql tutorial _ real_escape_string for filtering.

// If Magic Quotes is enabled

If (get_magic_quotes_gpc ()){
$ Name = stripslashes ($ name );
} Else {
$ Name = mysql_real_escape_string ($ name );
}

Mysql_query ("SELECT * FROM users WHERE name = '{$ name }'");

Note: The mysql_real_escape_string function is valid only when the mysql database connection is successful.

Define Quotes to determine whether it is enabled. if it is, use the strips tutorial lashes; otherwise, use the mysql tutorial _ real_escape_string to filter out. // If Magic Quotes is used...

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.