首页 > 解决方案 > PHP代码在浏览器上显示空白屏幕而不是内容

问题描述

当我用网络浏览器打开它时,下面带有 html 的 php 代码显示一个空白屏幕。我已经设置了一个 php 服务器来运行它。我究竟做错了什么?

        <!DOCTYPE html>
        <html>
        <head>
                <title>maro</title>
                <link rel="stylesheet" href="bootstrap.min.css">
                <link rel="stylesheet" href="custom.css">
          </head>
          <body>
                <div class="container-fluid">
                   <form action="imagesear.php" method="get">
                         <div class="row" id="bg">
                         <div class="col-sm-1" id="resdoodle">
                             <a href="index.html"><font color="#FF0000">m</font><font color="#FFA500">a</font><font color="#008000">r</font><font color="#0000FF">o</font></a>
                         </div>
                         <div class="col-sm-6" id="searchbx2">
                             <div class="input-group">
                                 <input type="text" class="form-control" name="search" id="boxstyle2" required>
                                 <span class="input-group-btn">
                                      <input type="submit" class="btn btn-secondary" name="search_btn" value="GO" id="btnstyle2">
                                 </span>
                             </div>
                         </div>
                     </div>
                </form>
            </div>
            <div class="result">    
                <?php
                $search=$_GET["id"];
                $_con=mysqli_connect("localhost","augustus","password");
                mysqli_select_db($_con,"websited");
                $_sql2="select * from webd where stitle like '%$search%'";
                $rs=mysqli_query($_con,$_sql2);
                if(mysqli_num_rows($rs)<1)
                                 {
                                  echo "<center><h4><b>Oops! No result found for your query</b></h4></center>";
                                  exit();
                                 }
                while($resul2=mysqli_fetch_assoc($rs))
                {
                    echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id="imgp"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }  
                ?>
            </div>
            <script src="jquery.min.js"></script>
            <script src="tether.min.js"></script>
            <script src="bootstrap.min.js"></script>
      </body>
</html>

我尝试对我的 php 服务器进行故障排除,但这很好,因为其他 php 代码运行良好。请帮助修复此代码

标签: phphtml

解决方案


对我来说,它返回了这个错误:

解析错误:语法错误,意外的 'imgp' (T_STRING),期待 ',' 或 ';' 在第 38 行的 /var/www/html/tmp/test.php 中

在这一行:

echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id="imgp"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

id="imgp" 在双引号内,在其他带双引号的字符串内。所以这就是问题所在。您需要将单引号放在其他带双引号的字符串中才能正常工作:

echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id='imgp'></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

也许错误不会出现在您面前,因为它们已被禁用。你可以试试这个,在 php 文档的开头:

error_reporting(E_ALL);

PS:用户也会出现错误,请谨慎使用。


推荐阅读