mysql_fetch_assoc错误,似乎无法找出问题所在 [英] mysql_fetch_assoc error, can't seem to figure out what the problem is

查看:65
本文介绍了mysql_fetch_assoc错误,似乎无法找出问题所在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
警告:mysql_fetch_array()期望参数1为资源,给定布尔值尝试创建php购物车时出现错误

Possible Duplicate:
“Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given” error while trying to create a php shopping cart

我在这里不断收到此错误:

I keep getting this error here:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ReadNotes\viewyournote.php on line 40

此处带有此代码:

<?php

//Starting session

session_start();

//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs

include ('includes/mass.php');

//Set the  session variable

$username = $_SESSION['username'];

//Get variables from form

$chapter = substr($_GET['chapter'],1,-1);

$id      = substr($_GET['note'],1,-1);

$user    = substr($_GET['user'],1,-1);

$author  = substr($_GET['author'],1,-1);

$book    = substr($_GET['book'],1,-1);

//Check if isset(username)///

        if (isset($username))

            //Execute view

            {

                $sql_to_view_the_note = "SELECT * FROM notes INNER JOIN small_note ON notes_id = '$id' AND authname = '$author' AND bookname = '$book' AND user = '$username'";

                $sql_view_query = mysql_query($sql_to_view_the_note);

                while ($view_row = mysql_fetch_assoc($sql_view_query))

                      {
                        //Define values to view to user

                        $author_v = $view_row['authname'];
                        $bookname_v = $view_row['bookname'];
                        $chapter_name_v = $view_row['chapter_name'];
                        $smallnote_v  = $view_row['small_note'];    

                      }     

                                    //Echo back author name and book name

                                    echo "<center>";

                                    echo "<br><br>";

                                    echo "<div id= 'authorname'>";

                                    echo "Author's Name: ";

                                    echo $author_v;

                                    echo "</div>";

                                    echo "</div>";

                                    //Echo back book name

                                    echo "<br>";

                                    echo "<div id= 'book_name'>";

                                    echo "Books Name: ";

                                    echo $bookname_v;

                                    echo "</div>";

                                    echo "</center>";

                                    //Echo back chapter

                                    echo "<br>";

                                    echo "<div id= 'book_name'>";

                                    echo "Chapter Name: ";

                                    echo $chapter_name_v;

                                    echo "</div>";

                                    echo "</center>";

                                    //Echo back note

                                    echo "<br>";

                                    echo "<div id= 'book_name'>";

                                    echo "Small notes: ";

                                    echo $smallnote_v;

                                    echo "</div>";

                                    echo "</center>";
            }





?>

推荐答案

在使用mysql_fetch_assoc

当查询执行失败时,mysql_query返回false(一个布尔值),而将其作为输入作为mysql_fetch_assoc的输入,则会出错.

When the execution of query fails mysql_query returns false ( a boolean) and when you give this as an input to mysql_fetch_assoc, you get your error.

在mysql_query之前打印查询,在mysql中运行它,看看它是否正常工作.

Print the query just before mysql_query, run it in mysql and see if it works correctly.

这篇关于mysql_fetch_assoc错误,似乎无法找出问题所在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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