How to debug this problem?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
masterphp
Forum Newbie
Posts: 11
Joined: Sun Apr 06, 2008 8:12 pm

How to debug this problem?

Post by masterphp »

I have the following replylist.php code, when I try to display on the page I got the error message"Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\htdocs\replylist.php on line 16." But it seems like nothing wrong with line 16, so can anyone help me with that, thanks!

Code: Select all

<!--sys_conf.inc:------------------------------>
<?php
  $DBHOST="localhost";
  $DBUSER="root";
  $DBPWD="12345";
  $DBNAME="guestbook";
?>
 

Code: Select all

<!--replylist.php:--------------------->
<?php   
    require_once("sys_conf.inc");
    //Initial
    $one_page_line=10;  //Max_Page
    $reply_content=array();     
    
    
    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);         
    mysql_select_db($DBNAME);
    $str="select content from reply where bookid =".$_GET["recordid"];
    $result=mysql_query($str,$link_id);
    
    
    $i=0;
    while(list($con)=mysql_fetch_row($result))
    {
        $reply_content[$i]=$con;
        $i++;
    }
    mysql_close($link_id);   
 
    $count =count($reply_content); 
?>
<html>
    <head>
        <title>Review for reply</title>
    </head>
    <body>
        <?php include  "head.html"?>
        <table width="68%" border="0"> 
            <tr> 
            <td>            
            <?php 
            $int_page_count=$count;  
            $int_page_num=ceil($int_page_count/$one_page_line);
            echo "<font color=#CC33FF>page separate:"; 
            for ($i=1;$i<=$int_page_num;$i++) 
            { 
                    echo "<a href=booklist.php?recordid=".$_GET["recordid"]."&page=$i>".$i."</a>&nbsp;"; 
            } 
            echo "</font>"; 
            ?> 
            </td>
            <td><p align=right>Total<font color=red><?echo "$count"?></font>Messages</p></td> 
            </tr>
        </table> 
        <table width="68%" border="0" align="center"> 
        <? 
        if (!isset($page) or $page=="") 
            $page=1; 
        $text="";
        $begin_line=$int_page_count-($page-1)*$one_page_line; 
        if ($begin_line<$one_page_line)
            $one_page_line=$begin_line; 
    
        for ($j=$begin_line;$j>($begin_line-$one_page_line);$j--) 
        {           
            print_r ($reply_content[$j-1]);
        }
        ?> 
        </table> 
        <p align=center><a href="#" onclick=history.back()>Return</a></p>
        </body>
</html>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: How to debug this problem?

Post by onion2k »

Your SQL query didn't return any results, so calling mysql_fetch_row fails. You should check if the are any records in the result with mysql_num_rows() before trying to fetch anything.
Post Reply