我正在制作一个用户可以找到其他用户的搜索栏,但我一直在“无法搜索”。这是我的代码:
<div class="widget widget_search">
<h4 class="widget-title">Search</h4><!-- /.widget-title -->
<div class="widget-details">
<form action="blog.php" class="search-form" method="post">
<input type="text" name="search" class="search" placeholder="Search for.." required>
<button type="submit" name = "submit" value = "search" class="search-submit"><i class="fa fa-search"></i></button>
</form>
</div><!-- /.widget-details -->
</div><!-- /.widget -->
<?php print("$output");?>
和我的php
<?php
mysqli_connect('localhost', '', '', '');
$output ='';
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z&]#i", "", $searchq);
$query = mysqli_query("SELECT * FROM Users WHERE username LIKE '%$searchq%'") or die("could not search!");
$count = mysqli_num_rows($query);
if($count == 0){
$output = 'There were no search results!';
}else{
while($row = mysqli_fetch_array($query)){
$name = $row['username'];
$dateofb = $row['dateofb'];
$id = $row['id'];
$output .= '<div> '.$name.' '.$dateofb.'</div>';
}
}
}
?>
答案 0 :(得分:0)
mysqli_connect('localhost', '', '', '');
应该是
$myMysqli = mysqli_connect('localhost', '', '', '');
然后
$myMysqli->mysqli_query()
请使用参数输入查询:)