Php if语句不起作用

Php if语句不起作用,php,post,if-statement,Php,Post,If Statement,我有一个php,它由一个if语句和几个elseif语句组成。由于某些原因,我无法让if语句返回真值并输出相应的消息。它与$\u POST方法无关(我认为),因为所有的elseif语句都使用它们的$\u POST方法。如果在相应字段中没有输入任何内容,我希望if语句返回一个真值 if(!isset($_POST['phpro_username'],$_POST['phpro_password'], $_POST['phpro_password1'])) { $messag

我有一个php,它由一个if语句和几个elseif语句组成。由于某些原因,我无法让if语句返回真值并输出相应的消息。它与$\u POST方法无关(我认为),因为所有的elseif语句都使用它们的$\u POST方法。如果在相应字段中没有输入任何内容,我希望if语句返回一个真值

if(!isset($_POST['phpro_username'],$_POST['phpro_password'], 
        $_POST['phpro_password1']))
{
    $message = 'Please enter a valid username and password';
}
/*check to make sure the form is the one 
 * from the browser*/
elseif ($_POST['form_token'] != $_SESSION['form_token'])
{
    $message = 'Invalid Form Submission';
}
elseif (strlen($_POST['phpro_username']) > 20 || 
        strlen($_POST['phpro_username']) < 4 ) 
{
    $message = 'Username Invalid';
}
if(!isset($\u POST['phpro\u username'],$\u POST['phpro\u password'],
$\u POST['phpro\u password1']))
{
$message='请输入有效的用户名和密码';
}
/*检查以确保表单是正确的
*从浏览器*/
elseif($\u POST['form\u token']!=$\u会话['form\u token'])
{
$message='提交的表单无效';
}
elseif(strlen($_POST['phpro_username'])>20 |
strlen($_POST['phpro_username'])<4)
{
$message='用户名无效';
}
在这之后还有一些其他的elseif语句,如果任何elseif语句都不正确,那么我就得到了正确的消息。这只是第一个不起作用的if语句。这是我发布变量的代码(密码/用户名)


创建用户名

创建密码

重新输入密码


我认为你的问题在于这不是你所期望的。如果发送带有空字段的表单,它们仍将在
$\u POST
中设置

您要检查它们是否:


不要对非html/js/css代码使用代码段。这次帮你修好了。这是有效的PHP吗?@cybermonkey哪部分?对我来说似乎是有效的…@MightyWork第一次使用这个网站,我没有看到php的代码片段交易?@Anonymous.X我刚刚遇到empty(),在我提交这个之后,我测试了它,它似乎工作正常谢谢你的回答,我曾经怀疑上面提到的@Anonymous.X这个空的field@ratrace123您没有检查PHP日志中的错误吗?如果你这么做了,它应该会显示出来。@cybermonkey是的,我通读了它们,看起来我的代码应该在工作。。
<form id="signup_form" action="adduser_submit.php" method="post">
<fieldset>
<p class="loginfield" id="Username">
<label for="phpro_username">Create Username</label><br>
<input type="text" id="phpro_username" name="phpro_username" value="" maxlength="20" />
</p>

<p class="loginfield" id="Password">
<label for="phpro_password">Create Password</label><br>
<input type="text" id="phpro_password" name="phpro_password" value="" maxlength="20" />
</p>

<p class="loginfield" id="Re-enter Password">
    <label for="phpro_password1">Re-enter Password</label><br>
<input type="text" id="phpro_password1" name="phpro_password1" value="" maxlength="20" />
</p>

<p>
<input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />

<div id="submit_button" >
<input type="submit" value="&rarr; Sign Up" />
</div>
</p>

</fieldset>
</form>
if(empty($_POST['phpro_username']) || empty($_POST['phpro_password']) || empty($_POST['phpro_password1'])) {
    //...
}