本文介绍了PHP/SQL,简单选择哪里获取“值";作为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$account = "proot";
$sql_check_account = mysqli_query($connect, "SELECT username FROM proot_accounts WHERE username = $account");
if(!$sql_check_account)
die(mysqli_error($connect));
返回:
where 子句"中的未知列proot"
Unknown column 'proot' in 'where clause'
同:
$sql_check_account = mysqli_query($connect, 'SELECT username FROM proot_accounts WHERE username = "'.$account.'"');
或者
$sql_check_account = mysqli_query($connect, "SELECT username FROM proot_accounts WHERE username =".$account);
什么可以使变量 $account 作为列执行?我不明白这里的问题...
What can make the variable $account perform as a column ? I don't get the problem here...
谢谢!
推荐答案
你需要在它周围加上引号.
You need to put quotes around it.
mysqli_query($connect, "SELECT username FROM proot_accounts WHERE username = '$account'");
您还应该探索 PHP 中准备好的 SQL 语句.他们将省去很多这些格式问题.
You should also explore prepared SQL statements in PHP. They will save a lot of these formatting headaches.
这篇关于PHP/SQL,简单选择哪里获取“值";作为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!