1

我是 php 编程的新手,我无法找到这段代码中的错误:

<p>
       <?php
            function check_input($data)
                {
                    $data = trim($data);
                    $data = stripslashes($data);
                    $data = htmlspecialchars($data);
                    $data = nl2br($data);
                    return $data;
                }
            $password = $_POST['password'];//security check on the input of the password

            if (isset($password))
            {
                if ($password == "hotdog")
                {
       ?>
                    Here is the secret NASA code: <br/>
                    <strong>RT4567EGST442YT3ZQS</strong>
       <?php
                else
                {
       ?>
                    The password is incorrect. <br/>
                    <a href="index.php">go and try here again</a>.
       <?php
                }
                }
            }
            else
            {
       ?>
                You have to put a password. thanks to retry on <a href="index.php">this page</a>.
       <?php
            }
       ?>
   </p> 

任何帮助将不胜感激!多谢。麦克风

4

2 回答 2

2

在您发布的代码的第 21 行附近,您缺少一个}. 改变

    <?php
            else
            {

    ?>

    <?php
            } else
            {
    ?>
于 2012-06-20T00:03:01.503 回答
1

您还在}第 28 行添加了太多。

这应该有效:

    <p>
   <?php
    function check_input($data)
        {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            $data = nl2br($data);
            return $data;
        }

        $password = $_POST['password'];//security check on the input of the password

        if (isset($password))
        {
            if ($password == "hotdog")
            {
   ?>
                Here is the secret NASA code: <br/>
                <strong>RT4567EGST442YT3ZQS</strong>
   <?php
            }
            else
            {
   ?>
                The password is incorrect. <br/>
                <a href="index.php">go and try here again</a>.
   <?php
            }
        }
        else
        {
   ?>
            You have to put a password. thanks to retry on <a href="index.php">this page</a>.
   <?php
        }
   ?></p> 
于 2012-06-20T00:12:19.323 回答