嵌套if-else

时间:2018-04-23 09:49:24

标签: php

我来自Java Swing编程,但我认为扩展我的PHP知识是有益的。所以,我今天才知道,有一种方法可以更清晰地在html中嵌入php。所以我所做的就是遵循这个可行的语法。

<?php if ($condition) : ?>
 //html here
<?php endif; ?>

但是当我将if-else嵌套到相同的语法时,我收到一个错误。顺便说一下,我正在使用PHP Storm。

<?php if (isset($_POST['uname']) && isset($POST_['psw'])) : ?>
    //start of nested if-else
    <?php if($isValid === 1) : ?>
        <script>alert('test')</script>
    <?php else : ?> // this line shows an error
        <script>alert('test')</script>
    <?php endif; ?>
    //end of nested if-else
<?php endif; ?>

下面是PHP Storm中错误指示器的图像。

enter image description here

错误表示它希望在此行上发表声明

<?php else : ?> // this line shows an error

我无法弄清楚是什么导致它。

感谢。

1 个答案:

答案 0 :(得分:2)

我收到了你的错误:

替换它:

<?php if (isset($_POST['uname']) && isset($POST_['psw'])) : ?>  // You are writing $POST_ but not $_POST

要:

<?php if (isset($_POST['uname']) && isset($_POST['psw'])) : ?>