我正在尝试编码一个搜索框,将通过我的数据库中的列进行搜索。如果搜索与列匹配,则会在下表中打印该记录。
我正在搜索一个包含公司记录的县的列。没有显示任何错误,但是,当我在数据库中搜索某个县时,表仍然为空。从理论上讲,我看不出我做错了什么,我认为代码应该可以工作!任何帮助都将不胜感激。
DBconnect.php
<?php
// connect to the database
$db = 'stylecraft_dev';
$host = 'localhost';
$user = 'stylecraft_admin';
$password = '000000';
$dbConn = mysql_connect($host,$user,$password) or die("Failed to connect to database");
$result = mysql_select_db($db, $dbConn) or die("Failure selecting database");
?>form.php
<?php
$sql = "SELECT * FROM member ";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search-box']);
$sql .= "WHERE MB_COUNTY = '{$search_term}' ";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<form name="search_form" method="POST" action="stockists.php">
Search: <input type="text" name="search_box" value=" "/>
<input type="submit" name="search" value="Search the stockists...">
</form>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
<td><strong>Company Name</strong></td>
<td><strong>Website</strong></td>
<td><strong>Phone</strong></td>
<td><strong>Address</strong></td>
</tr>
<?php while ($row = mysql_fetch_array($query)) {?>
<tr>
<td><?php echo $row['MB_COMPANY'];?></td>
<td><?php echo $row['MB_MOBILE'];?></td>
<td><?php echo $row['MB_PHONE'];?></td>
<td><?php echo $row['MB_COUNTY'];?></td>
</tr>
<?php } ?>
</table>https://stackoverflow.com/questions/28854671
复制相似问题