Php 在sql数据库中搜索主页时出错
在中搜索(例如:DUFF)会显示以下错误消息:Php 在sql数据库中搜索主页时出错,php,sql,search,Php,Sql,Search,在中搜索(例如:DUFF)会显示以下错误消息: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= '[]'OR name = '[]'OR team = '[]'' at line 1 Dreamweaver未找到语法错误。有人能帮我吗 <?php //Incl
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= '[]'OR name = '[]'OR team = '[]'' at line 1
Dreamweaver未找到语法错误。有人能帮我吗
<?php
//Include connection file
include "connection.php";
$sql = "SELECT * FROM PES_ONLINE_DATABASE";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE playerID = '[$search_term]'";
$sql .= "OR name = '[$search_term]'";
$sql .= "OR team = '[$search_term]'";
}
$Tabelle_anzeigen = mysql_query($sql) or die(mysql_error());
?>
<form name="search_form" method="POST" action="index.php">
Search: <input type="text" name"search_box" value=""/>
<input type="submit" name="search" value="Durchsuche die Datenbank"> </form>
<table width="70%" cellpadding="5" cellspacing="5">
<tr>
<td><strong>playerID</strong></td>
<td><strong>name</strong></td>
<td><strong>team</strong></td>
</tr>
<?php while ($row = mysql_fetch_array($Tabelle_anzeigen)) { ?>
<tr>
<td><?php echo $row["playerID"];?> </td>
<td><?php echo $row["name"];?> </td>
<td><?php echo $row["team"];?> </td>
</tr>
<?php } ?>
</table>
在or的前面放置如下空格
$sql .= " WHERE playerID = '[$search_term]'";
$sql .= " OR name = '[$search_term]'";
$sql .= " OR team = '[$search_term]'";
非常感谢你的帮助。但不知怎的。。。当我输入“DUFF”时,他什么也不返回,也许你知道问题出在哪里吗?试着打印你的查询echi$sql
并检查出了什么问题,不需要[]的简单输入“$search\u term”
Hm谢谢。。。它现在搜索,但总是给我相同的uOTP,但无论我搜索什么…您忘记了表单中名称
和搜索框
之间的等号。因此,$\u POST['search\u box']
为空。