前端之家收集整理的这篇文章主要介绍了
php校验表单检测字段是否为空的方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@本文实例讲述了PHP校验表单检测字段是否为空的方法。分享给大家供大家参考。具体如下:
@H_
502_0@
PHP校验表单,检测字段是否为空,当表单中有未填写的字段,则会
显示错误信息。
<div class="jb51code">
<pre class="brush:xhtml;">
,保存为: ErrorCheck.
PHP;">
PHP
$errorcount=0;
if (!trim($_POST['nickname'])) {
echo "
Nickname is @R_
301_103@.";
$errorcount++;
}
if (!trim($_POST['title'])) {
echo "
Title is @R_
301_103@.";
$errorcount++;
}
if ($errors > 0)
echo "
Please use your browser's back button " .
"to return to the form,and correct error(s)";
?>
PHP;">
" " (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.
"\0″ (ASCII 0 (0×00)),the NUL-byte.
"\x0B" (ASCII 11 (0x0B)),a vertical tab.