首页 > 解决方案 > PHP代码无法显示来自mysql数据库的数据

问题描述

我正在尝试准备一个 php 代码来从数据库中获取数据并在输入字段中输入关键字后将其显示在浏览器中。存放代码的文件名为resu.php 代码如下

       <!DOCTYPE html>
       <html>
       <head>
            <title>fade</title>
            <link rel="stylesheet" href="bootstrap.min.css">
            <link rel="stylesheet" href="custom.css">
        </head>
        <body>
            <div class="container-fluid">
                <form action="resu.php" method="get">
                     <div class="row" id="bg">
                         <div class="col-sm-1" id="resdoodle">
                             <a href="index.html"><font color="#FF0000">f</font><font color="#FFA500">a</font><font color="#008000">d</font><font color="#0000FF">e</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
                         $_con=mysqli_connect("localhost", "augustus", "password");
                         mysqli_select_db($_con,"webdata");
                         if(isset($_GET['search_btn']))
                         {
                             $search=$_GET['search'];
                             $_sql1="select * from websited where stitle like '%$search%'";
                             $rs1=mysqli_query($_sql1);
                             while($resul=mysqli_fetch_assoc($rs1))
                             {
                                 echo "<a href='".$resul[slink]."'><font size='4' color='#0000cc'> <b>".$resul[stitle]."</b> </font></a><br>";
                                 echo "<font size='3' color='#006400'> <b>".$resul[slink]."</b> </font><br>";
                                 echo "<font size='3' color='#666666'> <b>".$resul[sdesc]."</b> </font><br>";
                             }
                         }
                    ?>
                </div>
                <script src="jquery.min.js"></script>
                <script src="tether.min.js"></script>
                <script src="bootstrap.min.js"></script>
          </body>
    </html>

该代码正在检测数据库中关键字 YouTube 的存在,但无法显示条目。请帮忙。

标签: phphtml

解决方案


正如@Dharman 指出的那样,代码中的缺陷是第mysqli_query34 行的函数。正确的代码应该是

$rs1=mysqli_query($_con,$_sql1); 

并且$resul[slink]应该$resul['slink'] 与所有其他变量更正为相同。


推荐阅读