0

我似乎遇到了错误,通常一切都对我有用,但我很累,我似乎无法弄清楚我哪里出错了。

我收到这些错误:

Notice: Unknown column 'test' in 'where clause'SELECT * FROM settings WHERE player = `test` in C:\xampp\htdocs\ranking\search.php on line 18

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ranking\search.php on line 26


Unknown column 'test' in 'where clause'

这是我在 localhost 上使用的 php 代码。

<?php
//database infomation
$dbhost = "localhost";
$dbname = "databasesname";
$dbuser = "root";
$dbpass = "";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

if(isset($_POST['search'])) {
$searchinfo = $_POST['searchinfo'];
$type = $_POST['group1'];
if($type == "class"){

} else {
$query = "SELECT * FROM settings WHERE player = `$searchinfo`";
$result = mysql_query($query) or trigger_error(mysql_error().$query);

echo "<table><tr><th>Username</th>";
echo "<th> </th>";
echo "<th>Created</th>";
echo "<th>Infastructure</th>";
echo "<th>Statename</th>";
echo "<th>Money</th></tr>";
while ($row = mysql_fetch_array($result) or die($result."<br/><br/>".mysql_error())) { 
 echo '<tr><td>'
 . $row['player'] . '</td><td>'
 . $row['data_type'] . '</td><td>'
 . $row['data'] .  '</td><td> ';

 } }

}

?>
<html>
<head>
<rel href="includes/style.css" type="text/css">
<title> Ranking System for Herocraft | Search </title>
</head>
<center>
<div id="searchbar">
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<input type="radio" name="group1" value="username">Username
<input type="radio" name="group1" value="class">Class
<input name="searchinfo" id="searchinfo" size="30" value="Enter your search" maxlength="30" />
<input type="submit" name="search" value="search" /><br />
</form>
</div>
4

2 回答 2

7

您正在使用反引号在 SQL 查询中引用您的玩家姓名。反引号用于列名。

使用普通引号。

于 2013-04-24T03:08:38.837 回答
1

改变

$query = "SELECT * FROM settings WHERE player = `$searchinfo`";

$query = "SELECT * FROM settings WHERE player = '$searchinfo'";
于 2013-04-24T03:13:12.553 回答