我正在尝试为表单创建搜索栏,这是我的错误所在,对不起,我是PHP的新手,我将尽力解决此问题,
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\sampleform\crud.php on line 107
0 results
这是我的SQL命令正确的代码错误吗?
<?php
$conn = mysqli_connect($servername,$username,$password,$dbname);
if(!$conn) /* para ma connect sa database */
{
die("connection failed: " . mysqli_connect_error()); /*checking if connect*/
}
$sql = "SELECT * FROM tbl_friends".$search; /*dito yung SQL command*/
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
echo "<tr><form method ='post' action ='#'>
<td><input type ='hidden' name='id' value ='".$row['id']."'>".$row['id']."</td>
<td><input type ='text' name='fname' value ='".$row['name']."'></td>
<td><input type ='submit' name='edit' value ='EDIT'></td></form>
<td><button><a href='crud.php?del=".$row['id']."'>DELETE</a></button></td>
</tr>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
搜索过程
if (isset($_GET['search']))
{
$search = "WHERE name LIKE '%" .$_GET['search']. "%'";
}else
{
$search = "";
}
我的示例表单中的代码
<form action="#" method="post">
<div class="form-group" >
<input class="form-control input-sm" placeholder="Enter Name" name="fname" type="text">
<input type="submit" value="ADD FRIEND" class="form-control mb-2 " name="add">
</div>
</form>
<form action="#" method="get">
<div class="form-group">
<input class="form-control input-sm" placeholder="Enter Name" name="search" type="text">
<input type="submit" value="SEARCH" class="form-control mb-2 ">
</div>
</form>
<table class="table table-dark">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">EDIT</th>
<th scope="col">DELETE</th>
</tr>
</thead>