在我網站的成員頁面上,我需要一個選項,以便成員可以查找其他成員的信息。到目前爲止,我所做的就是創建一個搜索表單...將搜索表單連接到MySQL數據庫並顯示結果
<form id="searchform" name="searchform" action="searchresults.php" method="post">
Search Membership
<input type="text" name="search" id="textfield" placeholder="Search Members" />
<input type="submit" name="button" id="button" value="Search" />
</form>
我還創建了一個表在我的數據庫與所有成員的信息的。現在,我只需要幫助獲取表單與數據庫表進行通信,並將輸入內容輸入到搜索表單中,並將結果顯示在結果頁上。
我不熟悉這一點,任何幫助將不勝感激。謝謝。
UPDATE: 所以現在我有我的searchresults.php頁下面的PHP代碼...
<?php
error_reporting(-1);
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="MOAMemberSearch";
mysql_connect($host, $username, $password) or die("cannot connect");
mysql_select_db($db_name) or die("cannot select DB");
$sql = "SELECT * FROM MOAMemberSearch";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if (false === $result) {
echo mysql_error();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Member Search - MOA</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.ennui.contentslider.css" rel="stylesheet" type="text/css" media="screen,projection" />
<style type="text/css">
#content_wrapper #content table {
color: #000;
}
</style>
</head>
<body>
<div id="menu_wrapper">
<div id="menu">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="boardofdirectors.html">Board</a></li>
<li><a href="members.php" class="current">Members</a></li>
<li><a href="ratingcard.html">Rating Card</a></li>
<li><a href="join.html">Join MOA</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</div> <!-- end of menu -->
</div> <!-- end of menu wrapper -->
<div id="header_wrapper">
<div id="header"><!-- end of slider -->
</div>
<!-- header -->
</div>
<!-- end header wrapper -->
<div id="content_wrapper">
<div id="content">
<h1>Search Results</h1>
<table width="930" border="0" style="font-size:12px">
<tr>
<th>Sports</th>
<th>Last Name</th>
<th>First Name</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Phone 1</th>
<th>Phone 2</th>
<th>Email</th>
</tr>
<tr>
<td><?php echo $rows['Sports']; ?></td>
<td><?php echo $rows['LastName']; ?></td>
<td><?php echo $rows['FirstName']; ?></td>
<td><?php echo $rows['Address']; ?></td>
<td><?php echo $rows['City']; ?></td>
<td><?php echo $rows['State']; ?></td>
<td><?php echo $rows['Zip']; ?></td>
<td><?php echo $rows['Phone1']; ?></td>
<td><?php echo $rows['Phone2']; ?></td>
<td><?php echo $rows['Email']; ?></td>
</tr>
</table>
目前獲得在搜索結果應出現
是的,它的確如此。此錯誤非常常見,並且易於解決以下基本步驟。您的查詢失敗。你需要弄清楚爲什麼。至少有一個答案解釋了這一點,以及如何去做。 – 2014-10-19 16:50:51
我已經實施了您提供的「新」答案頁中的代碼。同樣的錯誤顯示。顯然它不能解決問題。所以介意解釋? – Patrick 2014-10-19 16:52:53
按照[此答案](http://stackoverflow.com/a/11674313/250259)中的步驟對此進行故障排除。對於初學者,您甚至沒有檢查過MySQL是否報告了什麼錯誤。這總是第一步。 – 2014-10-19 16:54:24