我正在編寫一些返回事件結果的代碼。在這張表中,我有一些填充MySQL數據的字段,包括證書的下載鏈接。PHP中的MySQL數據
但現在,我需要添加一個搜索字段。這是我迄今所做的:
<?php
include "open.php";
$sql = "SELECT * FROM results";
if (isset($_POST['search'])){
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE Name = '{$search_term}' ";
$sql .= "OR Place = '{$search_term}'";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<form name="search_form" method="POST" action="teste3.php">
Search: <input type="text" name="search_box" value="" />
<input type="submit" name="search" value="Search">
</form>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
<td>
<strong>Place</strong>
</td>
<td>
<strong>Name</strong>
</td>
<td>
<strong>Category</strong>
</td>
<td>
<strong>Certificate</strong>
</td>
</tr>
<?php while ($row = mysql_fetch_array($query)){ ?>
<tr>
<td><?php echo $row['Place']; ?></td>
<td><?php echo $row['Name']; ?></td>
<td><?php echo $row['Category']; ?></td>
<td>
<a href="http://(...)/<?php echo $row['Place']; ?>.pdf"
style="color: #000000" target="blank">Download Certificate</a>
</td>
</tr>
<?php } ?>
</table>
但由於某些原因,當我做了測試搜索,瀏覽器相呼應:
您的SQL語法錯誤;檢查 對應於你的MySQL服務器版本ulisses「‘在1號線
你錯過了'resultados'和'WHERE'當您連接它們之間的空間的方式。 – andrewsi
就是這樣。謝謝。 –