【发布时间】:2014-02-12 12:42:29
【问题描述】:
我对 php 和 MySQL 还很陌生,但我正在尝试运行一个查询,该查询将在我的数据库中搜索一个表,并从该条目中带回包含某些列的结果。
例如搜索邮政编码并带回:姓名、地址、联系电话、邮政编码。
谁能指出我缺少什么或哪里出错的正确方向。
以下是详细信息
最新更新
表格
<td><form action="searchresults.php" method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Find a Active Physio</strong></td>
</tr>
<tr>
<td width="100">Physio Reference</td>
<td width="301"><input name="PhysioReference" type="text" id="PhysioReference" /></td>
</tr>
<tr>
<td>Name of Physio</td>
<td><input name="Physio" type="text" id="Physio" /></td>
</tr>
<tr>
<td>Contact Number</td>
<td><input name="Number" type="text" id="Number" /></td>
</tr>
<tr>
<td>Address</td>
<td><input name="PhysiosAddress" type="text" id="PhysiosAddress" /></td>
</tr>
<tr>
<td>Postcode</td>
<td><input name="postcode" value="" type="text" id="postcode" />
<input type="submit" name="submit" value="Search" /></td>
</tr>
<tr>
<td>Physios Email</td>
<td><input name="PhysiosEmail" type="text" id="PhysiosEmail" /></td>
</tr>
<tr>
<td colspan="3" align="center"> </td>
</tr>
</table>
</form></td>
搜索结果
<?php
require_once('auth.php');
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="Physio"; // Table name
// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
if(!isset($_POST['postcode'])) {
header ("location:index.php");
}
$search_sql="SELECT * FROM `Physio` WHERE Postcode like '%".$_POST['postcode']."%'";
$search_query=mysql_query($search_sql);
$search_rs= mysql_num_rows($search_query) ;
echo "<p> Results </p>" ;
echo $_POST['{postcode'] ;
if ($search_rs > 0)
{
echo "<p>".$search_rs['Postcode'] ."</p>" ;
} else {
echo "NO Results found";
}
?>
【问题讨论】:
-
所有
mysql_*()函数都是officially deprecated (不再支持/维护),将来会是removed。您应该使用PDO 或MySQLi 更新您的代码,以确保未来的功能。