dscbxou1900343 2016-05-26 18:10
浏览 14
已采纳

从搜索栏中检索数据[重复]

This question already has an answer here:

I'm trying to create a search function on my website. I've been following a few videos etc on how to get it working but thus far the only reply I'm getting from my search bar is no results found. Could you guys take a look, to see where I have gone wrong. Thanks

$output = '';

if (isset($_POST['search'])){
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);

    $query = mysqli_query("SELECT * FROM loanusers WHERE username LIKE '%$searchq%' OR userid LIKE '%$searchq%'");
    $count = mysqli_num_rows($query);

    if ($count == 0) {
        $output = 'No results found';
    }else{
        while($row = mysqli_fetch_array($query)){
            $username = $row['username'];
            $userid = $row['userid'];

            $output .= '<div> '.$username.' '.$userid.' </div>';
        }
    }


}


 <body>
<form action="allusers.php" method="post">

<input type="button" name="Create User" value="Create New User" onclick="window.location.href='adminadduser.php'">
<input type="text" name="search" placeholder="Search Users...">
<input type="submit" value=">>">

</form>

<?php print("$output");?>

</div>
  • 写回答

1条回答 默认 最新

  • dtkz3186 2016-05-26 18:38
    关注

    mysqli_query takes a link identifier as its first argument. Create a connection to your database using mysqli_connect (there are examples for how to do this in the linked documentation) and use that connection variable in your mysqli_query statement.

    // create the link using appropriate values here
    $link = new mysqli($host, $user, $password, $db);
    
    // Then you can use the link to execute your query
    $query = mysqli_query($link, "SELECT * FROM loanusers... etc");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错