douzou8074 2018-06-11 17:05
浏览 43
已采纳

使用Like运算符使用php在url中显示输入的文本

Hi i have implemented search functionality by following in youtube but the problem is whenever i enter the name and click on search button it is displaying that entered text in URL as mentioned below.

    <?php session_start();



if(isset($_GET['search']))
{
    $valueToSearch=$_POST['valueToSearch'];
    $query="SELECT * FROM appointment WHERE 'first_name' LIKE '%".$valueToSearch."%'";
    $search=filtertable($query);

}
else{
    $query="SELECT * FROM appointment";
    $search_result=filtertable($query);
}

    function filterTable($query)
    {
        include 'includes/db.php';
        $filter_Result=mysqli_query($conn,$query);
            return $filter_Result;      
    }

  ?>

<form>

          <input name="valueToSearch" type="text"  placeholder="Search  by Name"/>

          <input type="submit" name="search" value="Search"/>

                <div class="body">
                    <div class="table-responsive">
                      <table class="table table-striped">
                        <thead>
                          <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Gender</th>
                            <th>Department</th>
                            <th>Phonenumber</th>

                          </tr>
                        </thead>
                        <tbody>
                          <?php
                             while ($row=mysqli_fetch_array($search_result)):?>


                                    <tr>

                                        <td><?php echo $row['appoin_id'];?></td>

                                        <td><?php echo $row['first_name'];?> </td>

                                        <td><?php echo $row['gender'];?></td>

                                        <td><?php echo $row['department'];?></td>

                                        <td><?php echo $row['phone_no'];?></td>

                                    </tr>

                                <?php endwhile;?>
                        </tbody>
                      </table>
                    </div>
                </div>
                </form>

it is displaying in the url as like this

http://website.com/admin/search.php?valueToSearch=df&search=Search

And displaying the error in error log as PHP Notice: Undefined index: valueToSearch in admin/search.php on line 7.

  • 写回答

1条回答 默认 最新

  • dongnao6858 2018-06-12 07:46
    关注
    <?php session_start();
    
    
    
    if(isset($_POST['search']))
    {
        $valueToSearch = $_POST['valueToSearch'];
        $query="SELECT * FROM appointment WHERE first_name LIKE '%".$valueToSearch."%'";        
        $search_result=filterTable($query);
    
    }
    else{
        $query="SELECT * FROM appointment";
        $search_result=filterTable($query);
        echo "No Records Found";
    }
    
        function filterTable($query)
        {
            include 'includes/db.php';
            $filter_Result=mysqli_query($conn,$query);
                return $filter_Result;      
        }
    

    ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上