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

Mathieu
  • 4,587
  • 11
  • 57
  • 112
  • 1
    You might be better with heredoc instead of all those nested tags... http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc – Adam Jun 20 '12 at 00:03
  • thanks i will check that – Mathieu Jun 20 '12 at 00:11

2 Answers2

2

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

    <?php
            else
            {

    ?>

to

    <?php
            } else
            {
    ?>
Asaph
  • 159,146
  • 25
  • 197
  • 199
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> 
edwardmp
  • 6,339
  • 5
  • 50
  • 77
  • i think i will also check out heredoc and nowdoc as suggested by Adam http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc – Mathieu Jun 20 '12 at 00:24
  • You should, but that has nothing to do with your question. – edwardmp Jun 20 '12 at 00:24
  • 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 – Mathieu Jun 20 '12 at 08:27
  • ok i had not spotted the place under the figure where i can 'tick' the correct answer. thanks. – Mathieu Jun 20 '12 at 18:20