【问题标题】:mysql_result() expects parameter 1 to be resource, boolean given [duplicate]mysql_result() 期望参数 1 是资源,给定的布尔值 [重复]
【发布时间】:2013-05-16 03:14:24
【问题描述】:

下面的代码给了我错误:

mysql_result() expects parameter 1 to be resource, boolean given

我已经仔细检查了我的数据库,所有表/字段名称都是正确的。

我会收到此错误还有其他原因吗?

if(isset($_GET['action']))
    {
        $action = $_GET['action'];
            if($action == "edit")
            {
                $pid = $_GET['id'];
                $query = "SELECT * FROM tbl_pages WHERE page_id = '$pid'";
                $content = mysql_query($query);
                $page_title = mysql_result($content, 0, 'page_title');
                $page_content = mysql_result($content, 0, 'page_content');
                echo "<form action=\"save.php\" method=\"post\">                                                                
                        Page Title: <input type=\"text\" name=\"pagetitle\" value=$page_title><br />                                    
                        <textarea id=\"editor1\" type=\"text\" name=\"pagecontent\">$page_content</textarea>
                        <script type=\"text/javascript\">CKEDITOR.replace( 'editor1' );</script>
                        <input type=\"submit\">
                      </form>";
            } else {
                echo "<a href=\"editpage.php?action=edit&id=3\"><li>Setting up program/Adjusting preference</li></a>
                        <a href=\"editpage.php?action=edit&id=4\"><li>Choosing plugins</li></a>
                        <a href=\"editpage.php?action=edit&id=5\"><li>Basic Features/Functions</li></a>
                        <a href=\"editpage.php?action=edit&id=6\"><li>Creating a Drum Beat/Envelopes</li></a>
                        <a href=\"editpage.php?action=edit&id=7\"><li>Creating a Bass Wobble</li></a>
                        <a href=\"editpage.php?action=edit&id=8\"><li>Utilizing Plugins</li></a>
                        <a href=\"editpage.php?action=edit&id=9\"><li>Advanced Tools/Features</li></a>";
            }
    } else {
        echo "<a href=\"editpage.php?action=edit&id=3\"><li>Setting up program/Adjusting preference</li></a>
                        <a href=\"editpage.php?action=edit&id=4\"><li>Choosing plugins</li></a>
                        <a href=\"editpage.php?action=edit&id=5\"><li>Basic Features/Functions</li></a>
                        <a href=\"editpage.php?action=edit&id=6\"><li>Creating a Drum Beat/Envelopes</li></a>
                        <a href=\"editpage.php?action=edit&id=7\"><li>Creating a Bass Wobble</li></a>
                        <a href=\"editpage.php?action=edit&id=8\"><li>Utilizing Plugins</li></a>
                        <a href=\"editpage.php?action=edit&id=9\"><li>Advanced Tools/Features</li></a>";    
    }

编辑:我仔细检查了连接和查询,仍然在努力寻找我出错的地方。除了使用 mysqli_query 之外,我在页面开头使用了一个非常相似的查询,mysqli 的等效 mysql_result 是什么?这有什么不同吗?

谢谢

【问题讨论】:

  • 在询问之前尝试搜索 SO.. 这样可以避免发帖..

标签: php mysql ckeditor


【解决方案1】:

mysql_connect() 你在哪里做的,还是你忘了做?

如果这不是问题,请更改

 $content = mysql_query($query);

进入

 $content = mysql_query($query) or die(mysql_error());

告诉我们你的错误是什么。

【讨论】:

  • 感谢回复'Parse error: syntax error, unexpected 'mysql_error' (T_STRING) in E:\xampp\htdocs\blog\editpage.php on line 167' 是给定的错误。
  • @Joe 我编辑了我的错误。我忘记了 die() 的括号
  • '未选择数据库'
  • 好吧,给你。你忘了做mysql_select_db("yourDbName") ...或者你可以在查询$query = "SELECT * FROM yourDbName.tbl_pages WHERE page_id = '$pid'";中命名数据库名称
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-23
  • 2012-09-10
  • 2016-10-30
相关资源
最近更新 更多