如何解决此问题:“警告:mysql_num_rows()期望参数1为资源,//"中给出的布尔值". [英] How to fix this :"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in //"?

查看:66
本文介绍了如何解决此问题:“警告:mysql_num_rows()期望参数1为资源,//"中给出的布尔值".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
mysql_fetch_array()期望参数1成为资源,在select中给出布尔值

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

//错误在第13行

$questions =$_POST['question_text'];

$checkquestion=mysql_query("SELECT question_text FROM questions LIKE '$questions' ");

if(mysql_num_rows($checkquestion)) { //line 13
echo "Question exist.";
                   }
else{

mysql_query("INSERT INTO questions (question_text,field_name)
VALUES ('$_POST[question_text]','$first_word')");
echo "Question saved";
                   }

推荐答案

$checkquestion = mysql_query("SELECT question_text FROM questions LIKE '$questions' ");
if (!$checkquestion) {
    die(mysql_error());
}

下一步:修正您的SQL查询.

Next step: Fix your SQL query.

您必须始终检查查询是否成功.它有上百万种可能出错,并且如果您的应用程序成功了,那么您将一劳永逸地进行操作:a)您将遇到与您无关的错误,并且b)无法有意义地调试自己的应用程序.

You must always check whether a query succeeded or not. There are a million possibilities for it to go wrong, and if your app just plows ahead assuming it succeeded you a) will get unrelated errors the way you do and b) won't be able to debug your own app meaningfully.

正如@alex指出的那样,在最终版本中,您应该做一些比这更优雅的错误处理.

As @alex points out, you should do some more elegant error handling than this in the final version.

这篇关于如何解决此问题:“警告:mysql_num_rows()期望参数1为资源,//"中给出的布尔值".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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