PHP:mysql_fetch_array() 期望参数 1 是资源,布尔值给定
可能的重复:
MySQL &PHP 参数 1 作为资源
我在我网站的标题中显示,但不知道这是什么类型的错误,我也不知道如何解决这个问题.有人可以帮我吗?
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();
?>
谢谢
推荐答案
根据 文档,mysql_query
在查询错误时返回 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());
相关文章