-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がリソースであると想定しています。ブール値はC:\ xampp \ htdocs \ AlumniAssociation\blog_written.phpの95行目にあります。

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 エラーを確認してください。

$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 に答える
0

データベース接続を作成しましたか? はいの場合は、接続を確認してください。mysql_query()接続が true を返す場合にのみ実行を試みます。

于 2012-12-18T12:54:25.213 に答える