当输入值为'0'时,empty($ _ POST ['var'])返回true [英] empty($_POST['var']) returns true when the input value is '0'

查看:312
本文介绍了当输入值为'0'时,empty($ _ POST ['var'])返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:




$

I have an input in a form like so

<input name='var' type='number'>

提交表单时,通过POST将输入发送到PHP文件。
在PHP文件中,通过检查

When the form is submitted, input is sent to a PHP file through POST. On the PHP file, it checks to see if the input is filled out by checking

empty($_POST['var'])

当我在文本框中输入'0'(零)并提交表单,尽管我尝试了print_r($ _ POST),'var'显然具有值'0',但PHP代码为空($ _ POST ['var'])返回'1'。

When I enter '0' (zero) into the textbox and submit the form, the PHP code returns '1' for empty($_POST['var']) even though I have tried print_r($_POST) and 'var' clearly has the value of '0'.

这是否应该发生?我是否也需要为这个异常检查== 0?谢谢。

Is this supposed to happen? Do I just need to also check for == 0 for this exception? Thanks.

推荐答案

要检查字段是否填充,请使用 isset($ _ POST ['var '])而不是空($ _ POST ['var'])

To check whether the field is filled or not, please use isset($_POST['var']) instead of empty($_POST['var']).

这篇关于当输入值为'0'时,empty($ _ POST ['var'])返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆