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

感情迁移 提交于 2019-11-28 14:20:42

问题


This question already has an answer here:

  • mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result 32 answers
  • mysql_result() expects parameter 1 to be resource, boolean given error [duplicate] 2 answers
  • mysql_result() expects parameter 1 to be resource, boolean given [duplicate] 3 answers

The code below gives me the error:

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

I have double checked my database and all table/field names are correct.

Are there any other reasons why I would get this error?

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>";    
    }

EDIT: I double checked the connection and query, still stuggling to find where ive gone wrong. I have used a very similar query at the start of the page except using mysqli_query, what is the equivalent mysql_result for mysqli? Does this make a difference?

Thanks


回答1:


Where do you do mysql_connect() or did you forget to do that?

If that is not the problem, change

 $content = mysql_query($query);

into

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

and tell us what your error is.



来源:https://stackoverflow.com/questions/16668560/mysql-result-expects-parameter-1-to-be-resource-boolean-given

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!