1

I'm a newbie in php programming and i can't make it finding where is the error in this piece of code:

<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> 

Any help will be appreciated! thanks a lot. Mike

2
  • 1
    You might be better with heredoc instead of all those nested <?php ?> tags... php.net/manual/en/… Commented Jun 20, 2012 at 0:03
  • thanks i will check that Commented Jun 20, 2012 at 0:11

2 Answers 2

2

Near line 21 in the code you posted, you're missing a }. Change

    <?php
            else
            {

    ?>

to

    <?php
            } else
            {
    ?>
Sign up to request clarification or add additional context in comments.

Comments

1

You also added a } too much on line 28.

This should work:

    <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 Comments

i think i will also check out heredoc and nowdoc as suggested by Adam php.net/manual/en/…
You should, but that has nothing to do with your question.
i'm new here on stackoverflow. i've pu that the "feedback was useful". How can i "mark it" if the answer is right. thanks
ok i had not spotted the place under the figure where i can 'tick' the correct answer. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.