gpt4 book ai didi

php - MySQL-错误 : Unknown column in where clause

转载 作者:行者123 更新时间:2023-11-30 00:49:28 25 4
gpt4 key购买 nike

<div class="ui-widget">

<form method="POST">
<?php

if(isset($_POST['search'])){

$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('hoppers');

$query = "SELECT user_name FROM users WHERE {$_POST['username']} = user_name";
$result = mysql_query($query) or die ("MySQL-Error: " . mysql_error());
$row = mysql_fetch_array($result);


if($row = TRUE){

$present = $row['user_name'];
echo $present;

}else{
echo "This User does not exist!";
}
}
?>

<label for="tags">Username: </label>
<input type="text" id="tags" name = "username">
<input type="submit" name="search" value="Suchen!">
</form>
</div>

所以我总是收到此错误消息:MySQL-Error: Unknown column 'dompol171' in 'where Clause'.
因此,它将我输入的用户名与“user_name”列本身进行比较。我一直很害怕......因为我不知道如何以不同的方式比较它!

最佳答案

这里发生的情况是 $_POST['username'] 的值被视为一列,因为您没有引用它,即将其设置为字符串。假设用户名是 musa,它会尝试将 musa 列与 user_name 列进行比较(并且该列不存在)。应该是

 $query = "SELECT user_name FROM users WHERE 'some username' = user_name";

关于php - MySQL-错误 : Unknown column in where clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21102124/

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