In SQL, how does one determine the passed null values?

Source: Internet
Author: User
In SQL, I have four <inputtype = & quot; text & quot; name = & quot;/& gt; is there any way to reasonably let the SQL statement on the php page judge whether the input value action is sent to the php page when the field is in SQL?
I have four Such input value
Action to php page for processing
Is there any way to reasonably let the SQL statement on the php page determine that when the field is blank, it will not be used as the search condition?
What other methods can be used in addition to the effort?
$ SQL = "select * from table where ..."


Instance:
Html


Chuli. php
// The database connection part is omitted.
$ SQL = "select * from student where name = '$ name' and age =' $ age' and sex = '$ sex' and height =' $ height '; // This is all
$ Result = mysql_query ($ SQL, $ con );

// Is there any way to judge the $ SQL statement when the Input data is null?
// If the input is 4 + 6 + 4 + 1 + 1 = 16, right? C41 + c42 + c43 + c44 + 1 = 4 + 6 + 4 + 1 + 1 = 16?

------ Solution --------------------
PHP code
Foreach (array_diff ($ _ POST, array ('') as $ k => $ v) $ r [] =" $ k = '$ V '"; $ SQL = "select * from student where ". join ('and', $ r );
------ Solution --------------------
It should be, the above should be less''

PHP code
$sql="select * from student where 1=1";if(!empty($_POST['name'])) $sql=" and name='$_POST[name]'";if(!empty($_POST['age'])) $sql=" and age='$_POST[age]'";if(!empty($_POST['sex'])) $sql=" and sex='$_POST[sex]'";if(!empty($_POST['height'])) $sql=" and height='$_POST[height]'";
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.