问题描述
我一直在MySQL中收到错误1054 - Unknown column 'apa_calda' in 'where clause'
.这是查询:
I keep getting the error 1054 - Unknown column 'apa_calda' in 'where clause'
in MySQL. Here is the query:
SELECT user_id FROM `detalii_contor` WHERE tip_contor=apa_calda
我想在PHP文件中使用此查询,但没有任何结果.因此,我尝试在SQL命令提示符下编写它.这是我在PHP文件中尝试过的内容:
I want to use this query in a PHP file but it doesn't give any results. So I tried to write it in the SQL command prompt.Here is what I tried in the PHP file:
$Q = "SELECT id_contor, den_contor FROM detalii_contor WHERE tip_contor='".$contor."'";
$Q = "SELECT id_contor, den_contor FROM detalii_contor WHERE tip_contor='$contor'";
即使没有""
或没有''
.
我想从表单中获取$contor
.我还尝试了$_POST['util']
和{$_POST['util']}
.我还尝试设置$contor
我需要的值,但没有结果.
I wanted to get $contor
from a form. I also tried with $_POST['util']
and {$_POST['util']}
. I've also tried to set $contor
the value I need, but no result.
推荐答案
字段值应该用引号引起来.
SELECT user_id FROM detalii_contor WHERE tip_contor='apa_calda'
Field value should be in quotes.
SELECT user_id FROM detalii_contor WHERE tip_contor='apa_calda'
顺便说一句,您应该始终逃避来自用户的一切.例如,
By the way, you should always escape everything that comes from users. For example,
$mysqli = new mysqli("host", "user", "password", "db");
$contor = $mysqli->real_escape_string($_POST['util'] );
$result = $mysqli->query(SELECT id_contor, den_contor FROM detalii_contor WHERE tip_contor='$contor'");
$mysqli = new mysqli("host", "user", "password", "db");
$contor = $mysqli->real_escape_string($_POST['util'] );
$result = $mysqli->query(SELECT id_contor, den_contor FROM detalii_contor WHERE tip_contor='$contor'");
这篇关于1054-'where子句'中的未知列'apa_calda'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!