我写了一个简单的页面脚本来循环访问数据库中的数据的动态表。但是,当我点击搜索页面返回空白,没有错误。我试图理解没有成功的情况。Php MysQl搜索脚本返回空白页
display_table.php
<?php
include('session.php');
if ($_SESSION['login_user']){
include 'includes/header.php';
$searchQ = "SELECT * FROM companytable";
if(isset($_POST['search'])){
$search_term = mysqli_real_escape_string($db, $_POST['search_box']);
$searchQ .="WHERE title ='{$search_term}' ";
$searchQ .="OR country ='{$search_term}' ";
$searchQ .="OR description ='{$search_term}' ";
$searchQ .="OR timezone ='{$search_term}' ";
}
$query = mysqli_query($db, $searchQ) or die(mysqli_error());
}
形式
<form class="form" name="search_form" method="POST" action="display_table.php">
<input id="search_box" style="padding: 2px;" class="" type="text" name="search_box">
<input class="btn btn-default" type="submit" name="search" value="🔍">
</form>
表
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>Address</th>
<th>Country</th>
<th>Time Zone</th>
</tr>
<?php while($company=mysqli_fetch_array($result)){ ?>
<tr>
<td data-th="ID"><?=$company['id'];?></a></td>
<td data-th="Name"><?=$company['title'];?></td>
<td data-th="Description"><?=$company['description'];?></td>
<td data-th="Type"><?=$company['type'];?></td>
<td data-th="Address"><?=$company['address'];?></td>
<td data-th="Country"><?=$company['country'];?></td>
<td data-th="Time Zone"><?=$company['timezone'];?></td>
</tr>
<?php };?>
</table>
相同空白页的回报。 – Skynet
您确认您正在创建的'$ searchQ'在结果中有任何行吗? – wogsland
好吧,我用'$ searchQ =“SELECT * FROM companytable LIMIT 5”;'来测试一次是否只返回5行并且它工作。所以我猜是的。 – Skynet