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 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计