gpt4 book ai didi

php - PHP 中的表 MySQL 数据

转载 作者:太空宇宙 更新时间:2023-11-03 12:16:43 25 4
gpt4 key购买 nike

我正在编写一些返回事件结果的代码。在此表中,我有一些字段填充了来自 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>

但出于某种原因,当我进行测试搜索时,浏览器会回显:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 'ulisses' OR Place = 'ulisses'' at line 1.

最佳答案

你需要提供一些空间作为

$sql .= " WHERE Nome = '{$search_term}' ";
$sql .= "OR Lugar = '{$search_term}'";

您完成查询的方式将变成

SELECT * FROM resultadosWHERE Nome = 'some val' OR Lugar = 'some val'

关于php - PHP 中的表 MySQL 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21835159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com