MySQL,fetch,num_rows错误

时间:2014-03-13 16:52:54

标签: php

好的,你好! 我最近有很多错误,所以我实际上不知道是什么导致这个错误,但这里是代码:

// Outputs all the banned IP's if any
function  fetch_banned() {
    $query = mysql_query("SELECTT * FROM ip_ban ORDER BY datetime DESC");
    if(mysql_num_rows($query) != 0) {
        // if found ips
        while($data = mysql_fetch_array($query)) {
            echo "<b>". $data['0'] ."</b> was banned on <b>". $data['1'] ."</b>";
        }
    } else {
        echo "There are No IP's banned!";   
    }
} 

?>

代码错误来自if(mysql_num_rows($ query)!= 0){

这是错误:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a3047131/public_html/core/inc/ipban.inc.php on line 37

我对编码很新,所以我很容易迷失在这些错误和东西中。

2 个答案:

答案 0 :(得分:2)

你的查询中有拼写错误SELECT应该是SELECT。

改变你的:

$query = mysql_query("SELECTT * FROM ip_ban ORDER BY datetime DESC");

为:

$query = mysql_query("SELECT * FROM ip_ban ORDER BY datetime DESC");

答案 1 :(得分:1)

SELECTT * FROM ip_ban ORDER BY datetime DESC

应该是

SELECT * FROM ip_ban ORDER BY datetime DESC