0

Here is a very basic html of what I am trying to do. The whole project is more complex, I'm creating a login site with js validation and php to verify username and password, and then submitting to either a guest page or admin page.

<!DOCTYPE html>
<html>
<head>
    <title>Exam | Guest</title>
    <meta name="keywords" content="exam, guest, cs319">
    <meta name="description" content="Guest access page.">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="exam.css" rel="stylesheet" type="text/css">
    <script src="exam.js"></script>
    </head>
 <body>
    <div id="container">
       <h1>Guest</h1>
    <?php>
        echo "<h2> $_REQUEST["message"] </h2>";
            ?>
     </div>
</body>
     </html>

Now, as written above this works, the page loads. Likewise, if I replace the php element above with this:

    <?php 
        if(isset($_REQUEST["message"])) {

         }
        else {

        }
    ?>

The page also loads. However, if I take the echo element from the first example, and put it into the if(isset()) from the second element, like so:

<h1>Login</h1>
    <?php 
        if(isset($_REQUEST["message"])) {
           echo "<h2> $_REQUEST["message"] </h2>";
         }
        else {

        }
    ?>

Then it doesn't work and the page doesn't load.

Tom
  • 9
  • 1

1 Answers1

1

You are using double-quotes for both your echo and $_REQUEST parameter. You will need to switch to single quotes for one or the other, as using double-quotes for both will cause a syntax error.

Note the syntax highlighting for the following string:

echo "<h2>$_REQUEST["message"]</h2>";

When reading your code, it attempts to echo "<h2> $_REQUEST[", and then runs into the m of message, which is unexpected. Also note that quoted keys will only work with the curly brace syntax.

Switching to the following will resolve this issue:

echo "<h2>" . $_REQUEST['message'] . "</h2>";

Hope this helps! :)

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • This is wrong, quoted keys only work using the curly brace syntax – Musa Jun 27 '17 at 01:54
  • @Musa -- Updated to correct this. – Obsidian Age Jun 27 '17 at 01:56
  • Afraid that didn't fix it. I still get the HTTP error 500 when loading the page with the echo nested inside the if function. I'm trying to use if(isset()) to pull a variable, "message" from the url. Edit: and fixed now. Concatenating it and changing the curly brace fixed it. Thank you! – Tom Jun 27 '17 at 01:58