简体   繁体   English

“where 子句”中的未知列“id”

[英]Unknown column 'id' in 'where clause'

Any idea why i might be getting this error when submitting to a DB?知道为什么我在提交到数据库时可能会收到此错误吗?

Unknown column 'id' in 'where clause' Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/somebody/public_html/sendmessage.php on line 41 “where 子句”中的未知列“id”警告:mysql_num_rows():在第 41 行的 /home/somebody/public_html/sendmessage.php 中,提供的参数不是有效的 MySQL 结果资源

while($success == FALSE) { 
$rand = rand(100000, 999999); 

$q = "SELECT * FROM $tablename WHERE id = '$rand'"; 
$r = mysql_query($q, $link);

echo mysql_error();


if(mysql_num_rows($r)) { **THIS IS LINE 41** 
    continue; 
} else { 
    $success = TRUE; 
} 
} 

Your table, whose name is stored in $tablename , does not have a column named id .您的表(其名称存储在$tablename中)没有名为id的列。 This makes the query fail, and all following database functions will also fail.这会使查询失败,并且所有以下数据库功能也将失败。

That doesn't look too nice there,那里看起来不太好,

first make sure you HAVE a column "id" in that table at all.首先确保您在该表中有一个“id”列。 and beware "id" is NOT "Id" nor "ID" nor "iD"!并注意“id”不是“Id”,也不是“ID”,也不是“iD”! After being absolutely sure you HAVE that column, and still getting an error, try it with quatation marks:在绝对确定您拥有该列后,仍然出现错误,请尝试使用引号:

$q = "SELECT * FROM ". $tablename ." WHERE 'id'='". $rand."'";

Try something like this.尝试这样的事情。 Thanks谢谢

while($success == FALSE) { $rand = rand(100000, 999999); while($success == FALSE) { $rand = rand(100000, 999999);

$q = "SELECT * FROM ". $tablename ." WHERE id = '". $rand ."'"; 
$r = mysql_query($q, $link);
$num_rows = mysql_num_rows($r);

echo mysql_error();


if($num_rows > 0) { **THIS IS LINE 41** 
    continue; 
} else { 
    $success = TRUE; 
} 
} 

Cheers!干杯!

Unknown column 'id' in 'where clause' “where 子句”中的未知列“id”

I ran into this error too, I discovered I was calling a different table that doesn't have id attributes.我也遇到了这个错误,我发现我正在调用一个没有 id 属性的不同表。 So I suggest you check your table name所以我建议你检查你的表名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM