duannao3819 2017-06-27 01:45
浏览 51

尝试获取if(isset())函数在echo中写入h2元素,但页面不加载。 [重复]

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.

</div>
  • 写回答

1条回答 默认 最新

  • donglangtun1850 2017-06-27 01:50
    关注

    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! :)

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等