回声'
  • ' PHP

    发布于 2024-12-06 10:20:48 字数 5971 浏览 1 评论 0原文

    当我这样做时:

    echo '<li></li>';
    

      内的 php 中,它会破坏 php 的其余部分并导致 '; ?> 显示在我的网站上。

    我正在尝试列出日记条目,以前已经做过很多次了,但现在似乎不起作用,这很奇怪。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <?php
    
    mysql_connect("localhost", "root");
    mysql_select_db("lunatic");
    
    ?>
    
    <title>Lunatic Cowboys - Gæstebog</title>
    
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/text.css" />
    <link rel="stylesheet" href="css/960.css" />
    <link rel="stylesheet" href="css/style.css" />
    
    </head>
    <body>
    <div id="headercont" class="container_12">
    <div id="header" class="grid_12"></div>
    <div id="navigation" class="grid_12">
    <ul>
        <li><a href="index.html">Forside</a></li><li> -</li>
        <li><a href="historie.html">Historie</a></li><li> -</li>
        <li><a href="klubben.html">Klubben</a></li><li> -</li>
        <li><a href="vedtaegter.html">Vedtægter</a></li><li> -</li>
        <li><a href="dansetider.html">Dansetider</a></li><li> -</li>
        <li><a href="instruktoer.html">Instruktør</a></li><li> -</li>
        <li><a href="kalender.html">Kalender</a></li><li> -</li>
        <li><a href="galleri.html">Galleri</a></li><li> -</li>
        <li><a href="http://lunaticcowboys.blogspot.com/" target="_blank">Blog</a></li><li> -</li>
        <li><a href="gaestebog.html">Gæstebog</a></li><li> -</li>
        <li><a href="links.html">Links</a></li><li> -</li>
        <li><a href="kontakt.html">Kontakt</a></li>
    </ul>
    </div>
    </div>
    
    <div id="contcont" class="container_12">
    <div id="content" class="grid_12">
    <h1 id="overskrift">Gæstebog</h1>
    
    </div>
    <div id="guestbook" class="grid_7">
    <h2>Se hilsner</h2>
    <ul>
    <?php 
        $eQuery = mysql_query("SELECT * FROM guestbook");
    
        while($entries = mysql_fetch_assoc($eQuery)){
            echo "<li></li>";
        }
    ?>  
    </ul>
    </div>
    <div id="add" class="grid_5">
    <h2>Skriv en hilsen</h2>
    <form id="guestbookform" method="post" action="add.html">
    <fieldset>
    
    <label for="name">Navn: </label>
    <input type="text" id="name" name="name"/><br />
    <label for="email">Email: </label>
    <input type="text" id="email" name="email"/><br />
    <label for="klub">Klub: </label>
    <input type="text" id="klub" name="klub"/><br />
    <label for="msg">Hilsen: </label>
    <textarea name="msg" id="msg" rows="8" cols="39" onfocus="this.value=null;">Skriv din hilsen her</textarea><br />
    <input type="button" onClick="javascript:addGreeting()" value="Send hilsen!" />
    </fieldset>
    </form>
    </div>
    <div id="copyright" class="grid_12">
    <p>2011© Copyright Lunatic Cowboys<br />Udvikling og design af <a href="http://alexkotsc.co.cc">Alexander Kotschenreuther</a></p>
    </div>
    </div>
    
    <script language="javascript" type="text/javascript">
    
    function addGreeting(){ 
    
    var aReq;
    
    try{
        // Opera 8.0+, Firefox, Safari
        aReq= new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            aReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                aReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    
    var name = document.getElementById('name').value;
    var email = document.getElementById('email').value;
    var klub = document.getElementById('klub').value;
    var msg = document.getElementById('msg').value;
    
    aReq.onreadystatechange = function(){
        if(aReq.readyState == 4){
            document.getElementById('add').innerHTML = aReq.responseText;
        }
    }
    aReq.open('GET', 'add.php' + '?name=' + name + '&email=' + email + '&klub=' + klub + '&msg=' + msg, true);
    aReq.send(null);
    

    }

    如您所见,没有未打开的标签。我真的不明白,我已经这样做了很多次了,从来没有遇到过问题。可能是什么原因造成的?

    屏幕截图:https://i.sstatic.net/UH68S.png

    Google Chrome 开发者工具屏幕截图:https://i.sstatic.net/0KdOm.png

    就像“渲染”时的 < ?php 标签被视为 < !--喜欢评论。

    When I do this:

    echo '<li></li>';
    

    in php inside a <ul>, it breaks the rest of the php and results in '; ?> showing up on my site.

    I'm trying to list journal entries and I've done it many times before, but it just doesn't seem to work now, which is very strange.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <?php
    
    mysql_connect("localhost", "root");
    mysql_select_db("lunatic");
    
    ?>
    
    <title>Lunatic Cowboys - Gæstebog</title>
    
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/text.css" />
    <link rel="stylesheet" href="css/960.css" />
    <link rel="stylesheet" href="css/style.css" />
    
    </head>
    <body>
    <div id="headercont" class="container_12">
    <div id="header" class="grid_12"></div>
    <div id="navigation" class="grid_12">
    <ul>
        <li><a href="index.html">Forside</a></li><li> -</li>
        <li><a href="historie.html">Historie</a></li><li> -</li>
        <li><a href="klubben.html">Klubben</a></li><li> -</li>
        <li><a href="vedtaegter.html">Vedtægter</a></li><li> -</li>
        <li><a href="dansetider.html">Dansetider</a></li><li> -</li>
        <li><a href="instruktoer.html">Instruktør</a></li><li> -</li>
        <li><a href="kalender.html">Kalender</a></li><li> -</li>
        <li><a href="galleri.html">Galleri</a></li><li> -</li>
        <li><a href="http://lunaticcowboys.blogspot.com/" target="_blank">Blog</a></li><li> -</li>
        <li><a href="gaestebog.html">Gæstebog</a></li><li> -</li>
        <li><a href="links.html">Links</a></li><li> -</li>
        <li><a href="kontakt.html">Kontakt</a></li>
    </ul>
    </div>
    </div>
    
    <div id="contcont" class="container_12">
    <div id="content" class="grid_12">
    <h1 id="overskrift">Gæstebog</h1>
    
    </div>
    <div id="guestbook" class="grid_7">
    <h2>Se hilsner</h2>
    <ul>
    <?php 
        $eQuery = mysql_query("SELECT * FROM guestbook");
    
        while($entries = mysql_fetch_assoc($eQuery)){
            echo "<li></li>";
        }
    ?>  
    </ul>
    </div>
    <div id="add" class="grid_5">
    <h2>Skriv en hilsen</h2>
    <form id="guestbookform" method="post" action="add.html">
    <fieldset>
    
    <label for="name">Navn: </label>
    <input type="text" id="name" name="name"/><br />
    <label for="email">Email: </label>
    <input type="text" id="email" name="email"/><br />
    <label for="klub">Klub: </label>
    <input type="text" id="klub" name="klub"/><br />
    <label for="msg">Hilsen: </label>
    <textarea name="msg" id="msg" rows="8" cols="39" onfocus="this.value=null;">Skriv din hilsen her</textarea><br />
    <input type="button" onClick="javascript:addGreeting()" value="Send hilsen!" />
    </fieldset>
    </form>
    </div>
    <div id="copyright" class="grid_12">
    <p>2011© Copyright Lunatic Cowboys<br />Udvikling og design af <a href="http://alexkotsc.co.cc">Alexander Kotschenreuther</a></p>
    </div>
    </div>
    
    <script language="javascript" type="text/javascript">
    
    function addGreeting(){ 
    
    var aReq;
    
    try{
        // Opera 8.0+, Firefox, Safari
        aReq= new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            aReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                aReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    
    var name = document.getElementById('name').value;
    var email = document.getElementById('email').value;
    var klub = document.getElementById('klub').value;
    var msg = document.getElementById('msg').value;
    
    aReq.onreadystatechange = function(){
        if(aReq.readyState == 4){
            document.getElementById('add').innerHTML = aReq.responseText;
        }
    }
    aReq.open('GET', 'add.php' + '?name=' + name + '&email=' + email + '&klub=' + klub + '&msg=' + msg, true);
    aReq.send(null);
    

    }

    No tags left unopened as you can see. I really don't get it, I've done this many times and I have never had a problem. What could be causing this?

    Screenshot: https://i.sstatic.net/UH68S.png

    Screenshot of Google Chrome developer tools: https://i.sstatic.net/0KdOm.png

    Its like when "rendered" the < ?php tags are considered < !-- like comments.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(2

    ︶葆Ⅱㄣ 2024-12-13 10:20:48

    我想我已经明白了。 PHP 未处理该请求 - 未执行任何 PHP 代码。如果你查看页面的源代码,你会发现你的整个PHP代码都在页面上可见。

    您是否在支持 PHP 的 Web 服务器上运行此程序,并且该 Web 服务器是否配置为将您正在使用的文件扩展名传递给 PHP?该文件是 .php 文件还是 .html 文件?

    编辑

    如果您希望 Apache 让 PHP 处理 .html 文件,请将这些行添加到 .htaccess 中,或将它们放入 httpd.conf 中并重新启动 Apache:

    AddHandler application/x-httpd-php .html
    AddHandler application/x-httpd-php .htm
    

    I think I have figured it out. PHP is not handling the request - no PHP code is being executed. If you view the source of the page, you will find that your entire PHP code is visible on the page.

    Are you running this on a PHP enabled web server, and is the web server configured to pass the file extension you are using to PHP? Is the file a .php file or a .html file?

    EDIT

    If you want Apache to get PHP to handle .html files, add these lines to a .htaccess, or put them in httpd.conf and restart Apache:

    AddHandler application/x-httpd-php .html
    AddHandler application/x-httpd-php .htm
    
    沫离伤花 2024-12-13 10:20:48

    现在在 php 代码之前或之后没有

      标签据说是因为问题 - 也许这是错误的事情?

    now there's no <ul> tag before or after the php code that is said to becausing the problem - maybe this is the wrong thing?

    ~没有更多了~

    关于作者

    0 文章
    0 评论
    503 人气
    更多

    推荐作者

    已经忘了多久

    文章 0 评论 0

    15867725375

    文章 0 评论 0

    LonelySnow

    文章 0 评论 0

    走过海棠暮

    文章 0 评论 0

    轻许诺言

    文章 0 评论 0

    信馬由缰

    文章 0 评论 0

      我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
      原文