未知列错误我尝试过多种方法

时间:2013-11-29 05:59:49

标签: php mysql

我得到一个未知的列错误,我似乎无法找到一个似乎可以帮助我的主题..这里的代码,但当我似乎删除$ query中的WHERE username = $ user或用引号替换$ user它似乎工作得很好。 (仅供参考我喜欢php的总菜鸟)

<?PHP

$id = "";
$username = "";
$email = "";
$nick = "";
$isMod = "";
$rank = "";
$joinDate = "";
$ip = "";
$coins = "";
$curHead = "";
$curFace = "";
$curNeck = "";
$curBody = "";
$curHands = "";
$curFeet = "";
$curPhoto = "";
$curFlag = "";
$curColor = "";

$db = mysql_connect("localhost","root","");
mysql_select_db("opencp", $db);

$user = $_GET['user'];

$query = "SELECT * from game_users WHERE username = ". $user. "";
$result = mysql_query($query);

if($result === FALSE) {
die(mysql_error());

}

echo "<?xml version=\"1.0\"\n";
echo "<products>\n";

while($line=mysql_fetch_array($result)){
echo "<item>" . $line['id'] . "</item>\n";
echo "<item>" . $line['username'] . "</item>\n";
echo "<item>" . $line['email'] . "</item>\n";
echo "<item>" . $line['nickname'] . "</item>\n";
echo "<item>" . $line['ismoderator'] . "</item>\n";
echo "<item>" . $line['rank'] . "</item>\n";
echo "<item>" . $line['joindate'] . "</item>\n";
echo "<item>" . $line['ips'] . "</item>\n";
echo "<item>" . $line['coins'] . "</item>\n";
echo "<item>" . $line['curhead'] . "</item>\n";
echo "<item>" . $line['curface'] . "</item>\n";
echo "<item>" . $line['curneck'] . "</item>\n";
echo "<item>" . $line['curbody'] . "</item>\n";
echo "<item>" . $line['curhands'] . "</item>\n";
echo "<item>" . $line['curfeet'] . "</item>\n";
echo "<item>" . $line['curphoto'] . "</item>\n";
echo "<item>" . $line['curflag'] . "</item>\n";
echo "<item>" . $line['colour'] . "</item>\n";

}

echo "</products>";

mysql_close($db);
?>

3 个答案:

答案 0 :(得分:1)

将其更改为,

$query = "SELECT * from game_users WHERE username = '". $user ."'";
$result = mysql_query($query);

您应该从PHP Strings开始。

注意: Please, don't use mysql_* functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDOMySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial

答案 1 :(得分:1)

username是一个字符串,所以它应该是单引号。

$user = $_GET['user'];  
$query = "SELECT * from game_users WHERE username = '". $user. "'"; 
$result = mysql_query($query); 

答案 2 :(得分:0)

这里有几个答案,但我想我会指出,因为你的字符串是双引号,你可以通过不使用连接(句号)样式来减少混淆:

$query = "SELECT * from game_users WHERE username = '$user ' ";

变量在php中用双引号替换,但不在单引号字符串中。