How does php judge non-null variables?

Source: Internet
Author: User
When a user submits a form, multiple variables will appear. How to make a non-empty judgment on each variable and input all the data into the database after all the variables are non-empty. I only know that empty () can be used to identify and output prompts, but I do not know how to implement all variables are not empty before putting... when a user submits a form, multiple variables will appear. How to make a non-empty judgment on each variable and input all the data into the database after all the variables are non-empty.
I only know that empty () can be used to identify and output prompts, but I do not know how to implement it.
All variables are not empty before entering all data into the database.
As shown in the following figure, I can use a switch to output a prompt when there are unfilled items, but it cannot be implemented.
All variables are non-empty before entering data.


  GetData ($ SQL); $ name = strip_tags ($ _ REQUEST ['name']); $ reviewer = $ _ REQUEST ['Referer']; $ review = $ _ REQUEST ['review']; $ SQL = "INSERT INTO 'remark' ('name', 'review', 'Referer', 'time ') VALUES ('". $ name. "','". $ review. "','". $ reviewer. "', NOW ()"; $ mysql-> runSql ($ SQL); if ($ mysql-> errno ()! = 0) {die ("Error:". $ mysql-> errmsg () ;}$ mysql-> closeDb (); echo $ mysql-> errmsg ()?>

Reply content:

When a user submits a form, multiple variables will appear. How to make a non-empty judgment on each variable and input all the data into the database after all the variables are non-empty.
I only know that empty () can be used to identify and output prompts, but I do not know how to implement it.
All variables are not empty before entering all data into the database.
As shown in the following figure, I can use a switch to output a prompt when there are unfilled items, but it cannot be implemented.
All variables are non-empty before entering data.


  GetData ($ SQL); $ name = strip_tags ($ _ REQUEST ['name']); $ reviewer = $ _ REQUEST ['Referer']; $ review = $ _ REQUEST ['review']; $ SQL = "INSERT INTO 'remark' ('name', 'review', 'Referer', 'time ') VALUES ('". $ name. "','". $ review. "','". $ reviewer. "', NOW ()"; $ mysql-> runSql ($ SQL); if ($ mysql-> errno ()! = 0) {die ("Error:". $ mysql-> errmsg () ;}$ mysql-> closeDb (); echo $ mysql-> errmsg ()?>

function is_empty_variable($variable){    return (!isset($variable) || trim($variable)==='');}

For the $ _ REQUEST array:

Foreach ($ _ REQUEST as $ key => $ value) {if (is_empty_variable ($ value) {throw new \ Exception ("{$ key} is blank ");}}

$ Error = array ("name" => "name required", "reviewer" => "username required", "review" => "comment required "); foreach ($ error as $ name => $ str) {if (! Isset ($ _ REQUEST [$ name]) | trim ($ _ REQUEST [$ name]) === "") die ($ str );}

You may be inspired to give a question.

Isset ($ _ REQUEST ['name']) & $ _ REQUEST ['name']

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.