In SQL, condition fields and table field names are the same, resulting in full table query.

Source: Internet
Author: User
Dear friends, I am a little Cainiao. In practice, I found a statement similar to the following: {code ...} $ sid indicates the value passed from the front end. seller_item_classify indicates that the sid indicates a field name in the table. if the value passed by $ sid is exactly & #039; sid & #039; the SQL w... dear friends, I am a little Cainiao. In practice, I found that the statement is similar to the following:

SELECT * FROM seller_item_classify where sid=$sid order by cweight asc ;

$ Sid indicates the value passed from the front end. seller_item_classify indicates that the sid indicates a field name in the table;
If the value passed by $ sid is 'Sid ', the SQL where statement becomes invalid, resulting in full table query;

Because in the production environment, the value of $ sid may be a numerical value or a char. Should I filter the value input at the front end in php?

What do you think of this question?

Reply content:

Dear friends, I am a little Cainiao. In practice, I found that the statement is similar to the following:

SELECT * FROM seller_item_classify where sid=$sid order by cweight asc ;

$ Sid indicates the value passed from the front end. seller_item_classify indicates that the sid indicates a field name in the table;
If the value passed by $ sid is 'Sid ', the SQL where statement becomes invalid, resulting in full table query;

Because in the production environment, the value of $ sid may be a numerical value or a char. Should I filter the value input at the front end in php?

What do you think of this question?

"SELECT * FROM seller_item_classify where sid='$sid' order by cweight asc ;"

For front-end input values, the backend must be filtered. SQL preprocessing is recommended.

Add ''to all SQL condition values''

sid = '$sid'

As AliasGood?

You can solve the problem by adding single quotes.

'Select * FROM seller_item_classify where sid = '. $ sid. 'Order by cweight asc ;'
Use pdo for preprocessing


  
Related Article

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.