Keyword Analysis of php filter SQL Injection-PHP source code

Source: Internet
Author: User
1. Use mysql_real_escape_string instead of addslashes to escape the input. 2. Add single quotation marks on both sides of the field value. 1. Use mysql_real_escape_string to escape the input. 2. Add single quotes on both sides of the Field Value

Script ec (2); script

Replacing update in SQL with str_replace is an error because:

If the SQL statement contains an update field, for example

The Code is as follows:
$ SQL = "update content = 'Update your name .. 'where userid = 1"

So what are the consequences of replacing str_replace? As long as the content submitted by the user contains an update,

Are delete and alter all Tampered? What a terrible thing !!!

So what is the correct solution?

The Code is as follows:
$ Content = mysql tutorial _ real_escape_string ($ content );
$ SQL = "update content = '$ content' where userid = 1

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.