这是search.php的代码
<?php include_once('include/header.php'); ?>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
require_once 'db/db.php';
$strKeyword = NULL;
if (isset($_POST["txtKeyword"])) {
$strKeyword = $_POST["txtKeyword"];
}
?>
<form name="frmSearch" method="post" action="search.php">
<table >
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword; ?>">
<input type="submit" value="Search"></th>
</tr>
</table>
<br>
</form>
<?php
$perpage = 2;
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
$start = ($page - 1) * $perpage;
$sql = "SELECT * FROM customer_info WHERE cust_ic LIKE '%" . $strKeyword . "%' OR cust_hp_contact1 LIKE '%" . $strKeyword . "%' limit {$start} , {$perpage}";
$query = mysqli_query($conn, $sql);
?>
<table class="table table-hover">
<thead>
<tr>
<th>Number</th>
<th>Gender</th>
<th>Race</th>
<th>IC Number</th>
<th>Name</th>
<th>Address</th>
<th>Contact Number (Home)</th>
<th>Handphone Number</th>
<th>Email</th>
<th>Join Date</th>
<th>Action</th>
</tr>
</thead>
<?php
$no = 1;
while ($result = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
?>
<tr>
<td><?php echo $no ?></td>
<td><?php echo $result['cust_gender'] ?></td>
<td><?php echo $result['cust_race'] ?></td>
<td><?php echo $result['cust_ic'] ?></td>
<td><?php echo $result['cust_name'] ?></td>
<td><?php echo $result['cust_add1'] ?>
<?php echo $result['cust_add2'] ?>
<?php echo $result['cust_postcode'] ?>
<?php echo $result['cust_town'] ?>
<?php echo $result['cust_state'] ?></td>
<td><?php echo $result['cust_home_con'] ?></td>
<td><?php echo $result['cust_hp_contact1'] ?>
<?php echo $result['cust_hp_contact2'] ?></td>
<td><?php echo $result['cust_email'] ?></td>
<td><?php echo $result['cust_join_date'] ?></td>
<td>
<a href="crud/edit.php?id=<?php echo $result['id']; ?>">Edit</a> ||
<a href="crud/delete.php?id=<?php echo $result ['id']; ?>">Delete</a>
</td>
</tr>
<?php
$no++;
}
?>
</table>
<?php
$sql2 = "select * from customer_info ";
$query2 = mysqli_query($conn, $sql2);
$total_record = mysqli_num_rows($query2);
$total_page = ceil($total_record / $perpage);
?>
<nav>
<ul class="pagination">
<li>
<a href="search.php?page=1" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<?php for ($i = 1; $i <= $total_page; $i++) { ?>
<li><a href="search.php?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php } ?>
<li>
<a href="search.php?page=<?php echo $total_page; ?>" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
<?php
mysqli_close($conn);
?>
<?php include_once('include/footer.php'); ?>
</body>
</html>
本页直接显示我从数据库的结果。我怎么能点击搜索按钮,并显示我的结果,不希望自动显示的结果没有我点击搜索按钮。
你应该得到post
请求的记录,而不是get
请求的记录。
if (isset($_POST["txtKeyword"])) {
$strKeyword = $_POST["txtKeyword"];
// execute query here
sql = "SELECT * FROM customer_info WHERE cust_ic LIKE '%" . $strKeyword . "%' OR cust_hp_contact1 LIKE '%" . $strKeyword . "%' limit {$start} , {$perpage}";
$query = mysqli_query($conn, $sql);
}