-3
$idno = $_GET['id'];
$identity = $idno;
$result = mysql_query("SELECT * FROM bloggings WHERE id ='$idno'");

while ($row = mysql_fetch_array($result))
{
    ...
}

$resu = mysql_query("SELECT * FROM comment WHERE id='$identity'");
while ($row = mysql_fetch_array($resu))
{
    ...
}

我得到了这样的错误:

警告:mysql_fetch_array() 期望参数 1 是资源,在第 95 行的 C:\xampp\htdocs\AlumniAssociation\blog_written.php 中给出的布尔值

4

3 回答 3

2

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

This error means that your query failed for some reason. On failure, mysql_query() returns false. It is usually due to a syntax error, missing field/table or no connection to the database.

You should test for the query failing so that you never pass a boolean to mysql_fetch_array():

$result = mysql_query("SELECT * FROM bloggings WHERE id ='$idno'");

if($result)
{
    while ($row = mysql_fetch_array($result))
    {
        ...
    }
}
else
{
    // query failed - see mysql_error()
}

There is no problem with having multiple fetch_* calls on the same page, as long as you are using different result resources (otherwise it will move the pointer forward each time).

Side note: mysql_* is deprecated, it is recommended to upgrade to MySQLi or PDO. Your code is vulnerable to SQL Injection, use a parameterised query instead of manually interpolating variables into the query.

于 2012-12-18T09:01:34.073 回答
0

您是否创建了数据库连接?如果是,请检查连接。并尝试mysql_query()仅在连接返回 true 时运行。

于 2012-12-18T12:54:25.213 回答
0

检查数据库连接然后mysql错误。

$result = mysql_query("SELECT * FROM bloggings WHERE id ='$idno'");
if (!$result) { // add this check.
   die('Invalid query: ' . mysql_error());
}
于 2012-12-18T09:02:53.240 回答