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']