我似乎遇到了错误,通常一切都对我有用,但我很累,而且似乎无法找出我要去哪里。
我收到以下错误:
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'
这是我在本地主机上使用的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>
最佳答案
您正在使用反引号在SQL查询中引用您的播放器名称。反引号用于列名。
使用普通引号。