开发者

MySQL error: Unknown column in 'field list'

I get the following error every time I attempt to run my script;

Unknown column '3624dfaf5f3429fc' in 'fie开发者_JAVA技巧ld list'

Here is my script, well the parts that matter anyway;

$num1 = mt_rand(1, 2147483647);
$num2 = mt_rand(1, 2147483647); 
$valcode = dechex($num1).dechex($num2);
$query = "SELECT COUNT(*) FROM records WHERE valcode='$valcode'";
$result = mysql_query($query) or die("Query failed because ".mysql_error());

If I change $valcode to an integer ($num1) it runs fine. On the other hand, as a hexidecimal it leads to said error. Any ideas why?


I suspect that error comes from a different query where you did not surround the code with single quotes. That would result in the query being valid when it's an integer but not when it's a hex string not surrounded by quotes. A string without quotes is interpreted as an identifier (a column name or alias).

i.e.

SELECT COUNT(*) FROM records WHERE valcode = 123

is valid, comparing valcode to the number 123,

SELECT COUNT(*) FROM records WHERE valcode = 3624dfaf5f3429fc

is not valid, as it tries to compare valcode to a column or alias named 3624dfaf5f3429fc. I don't believe the code you shared can lead to that error message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜