PHP:mysql_fetch_array()期望参数1为资源,给定布尔值 [英] PHP: mysql_fetch_array() expects parameter 1 to be resource, boolean given

查看:107
本文介绍了PHP:mysql_fetch_array()期望参数1为资源,给定布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
MySQL& PHP参数1为资源

Possible Duplicate:
MySQL & PHP Parameter 1 as Resource

我的网站标题中显示我,这不是什么错误,我也不知道如何解决.谁能帮我吗?

I am getting shown in the title on my website and don't what kind of error this is, neither do I know how to fix this. Can anyone help me?

这是add_answer.php文件:

This is the add_answer.php file:

<?php
    include("mysql_forum_test.php"); // Get value of id that sent from hidden field
$id=$_POST['id'];

// Find highest answer number.
$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);

// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1
if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}

// get values that sent from form
$a_name=$_POST['a_name'];
$a_email=$_POST['a_email'];
$a_answer=$_POST['a_answer'];

$datetime=date("d/m/y H:i:s"); // create date and time

// Insert answer
$sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')";
$result2=mysql_query($sql2);

if($result2){
echo "Successful<BR>";
echo "<a href='index.php?content=view_topic?id=".$id."'>View your answer</a>";

// If added new answer, add value +1 in reply column
$tbl_name2="forum_question";
$sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'";
$result3=mysql_query($sql3);

}
else {
echo "ERROR";
}

mysql_close();
?>

谢谢

推荐答案

根据文档如果查询错误,则返回FALSE.因此,您对mysql_fetch_array的参数是布尔值.使用mysql_error函数查看SELECT查询出了什么问题.

Per the documentation, mysql_query returns FALSE on an error with the query. Because of this, your argument to mysql_fetch_array is a boolean. Use the mysql_error function to see what's wrong with the SELECT query.

例如,

$result=mysql_query($sql) or die(mysql_error());

这篇关于PHP:mysql_fetch_array()期望参数1为资源,给定布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆