-3

可能重复:
警告:mysql_num_rows() 期望参数 1 是资源,给定的布尔值

我正在尝试让我的论坛系统运行,但我不断收到此错误:

警告:mysql_num_rows() 期望参数 1 是资源,第 26 行给出的布尔值

大多数代码只经历一个错误。这是我的完整代码:

<?php
include_once "../ads/connect_to_mysql.php";//Connect to Database

//Get section ID from the url varible coming in
if(isset($_GET['id'])&&$_GET[id]!=""){
    $sid=preg_replace('#[^0-9]#i','',$_GET['id']); //filter all characters except
}else{
    echo "ERROR: Variables to run this script have been removed from the URL";
    exit();
}
//Query the database for that section id, make sure it exists and get section title
$sql=mysql_query("SELECT*From ad_sections WHERE id='$sid' LIMIT 1");
$numRows=mysql_num_rows($sql);
if($numRows<1){
    echo "ERROR: That section does not exist, you have tampered with our URLs.";
    exit();

}
while($row=mysql_fetch_array($sql)){
    $sectionTitle=$row["title"];

}
//Use the section ID to query a "ad_posts" table in the database to get all the threads for this section
$sql=mysql_query("SELECT*From ad_sections WHERE type='a'AND section_id='$sid' ORDER BY date_time DESC LIMIT 25");  
$dynamicList="";
$numRows=mysql_num_rows($sql);
if($numRows<1){
    $dynamicList="There are no classifieds in this section yet. You can be the first to post.";
}else{
    while($row=mysql_fetch_array($sql)){
    $thread_id=$row["id"];
    $thread_Title=$row["thread_title"];
    $dynamicList.='<a href="view_thread.php?id=' . $thread_id . '">' . $thread_Title . '</a><br/>';
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html, charset=utf-8"/>
<title><?php echo "title"; ?></title>
<style>
</style>
</head>
<body>
<table style="bacground-color: #f0f0f0; border:#069 1px solid; border-top:none; width="900">
<tr>
<td width="731"><h2><?php echo $sectionTitle; ?><h2><?php echo $dynamicList; ?></td>
<td width="189">&nbsp;</td>
</tr>
</table>
</body>
</html>

这是第 26 行,真的碰壁了:

$numRows=mysql_num_rows($sql);
4

2 回答 2

0

它关于你$sql有一个错误

尝试这个

    $sql=mysql_query("SELECT * From ad_sections WHERE id='$sid' LIMIT 1");
                            ^-^-----spaces here
于 2013-01-05T22:04:01.103 回答
0

阅读手册

mysql_query() 成功时返回资源,错误时返回 FALSE。

...

如果用户无权访问查询引用的表,mysql_query() 也会失败并返回 FALSE。

于 2013-01-05T21:55:16.143 回答