PHP: mysql_fetch_array() expects parameter 1 to be resource, boolean given(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());
这篇关于PHP:mysql_fetch_array() 期望参数 1 是资源,布尔值给定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:mysql_fetch_array() 期望参数 1 是资源,布尔值给定
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
