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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?