Home >Backend Development >PHP Tutorial >How to check whether a field is empty in a PHP verification form_PHP Tutorial

How to check whether a field is empty in a PHP verification form_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:01:321111browse

How to detect whether a field is empty in a PHP verification form

This article mainly introduces how to detect whether a field is empty in a PHP verification form, involving techniques for PHP verification forms , very practical value, friends in need can refer to it

The example in this article describes the method of PHP verification form to detect whether the field is empty. Share it with everyone for your reference. The details are as follows:

PHP verifies the form and detects whether the fields are empty. When there are unfilled fields in the form, an error message will be displayed.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Contact Information



1 2

3

4

5

6

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

$errorcount=0;

if (!trim($_POST['nickname'])) {

echo "
Nickname is required.";

$errorcount ;

}

if (!trim($_POST['title'])) {

echo "
Title is required.";

$errorcount ;

}

if ($errors > 0)

echo "

Please use your browser's back button " .

"to return to the form, and correct error(s)";

?>

7 8

9

10

11

1

2

3

4

5

6

" " (ASCII 32 (0×20)), an ordinary space.

"t" (ASCII 9 (0×09)), a tab.

"n" (ASCII 10 (0x0A)), a new line (line feed).

"r" (ASCII 13 (0x0D)), a carriage return.

"

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn