Isset()函数的问题 [英] Issue With Isset() Function
本文介绍了Isset()函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图通过测试和尝试方法来学习PHP我正在努力解决isset()问题. 这是我的代码:
Trying to learn PHP with test and try method I am struggling with isset(). Here is the code I have:
<form action="validate.php" method="POST">
<label title="User Input"> Custom Header Name</label>
<input type="text" name="user_input">
<button type="submit" id="pageName">Submit</button>
</form>
PHP文件为
<?php
if(isset($_POST['user_input']))
{
echo "Input Is Set";
} else{
echo "Not Yet Set";
}
?>
我都遇到两种情况(输入为空或填充),结果是我收到第一条消息输入已设置"! 您能告诉我为什么会这样吗?
I both cases(empty or filled input) I am getting the first message "Input Is Set" as result! Can you please let me know why this is happening?
推荐答案
这是因为user_input
具有isset
一旦表单也被提交(如果未填写),为避免错误,只需添加!empty
check
This is because user_input
have isset
once form is submitted also if it is not filled, to avoid the error simply add an !empty
check
if(isset(($_POST['user_input'])) && (!empty($_POST['user_input'])))
这篇关于Isset()函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文