Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having a problem with mysql_fetch_array()...

    So, here it is:
    On my computer I have Apache2 with PHP5..
    I'm writing all my codes on this system.

    So I built a simple code with mysql_fetch_array().. On my Comp. it works great,
    but when i uploaded it to some hosting company (who uses php5 too) it dosent work.

    Here is my code:
    PHP Code:
    <?php
        $link 
    mysql_connect ($dbhost$dbusername$dbpass)
            or die (
    "Can not connect to MySQL");
        if (
    mysql_select_db ($dbname)) {
            
    $result mysql_query ("Select * from GuestBook order by gb_index desc");
            if (
    mysql_affected_rows() == 0) {
                echo 
    "<font face='Arial' size='2'>ÓÚ´ Ű°Ô˛ °˛Úň­ň˙.</font>\n";
            } else {
                while (
    $row mysql_fetch_array ($result)) {

                    echo 
    "<html dir='rtl'>\n";
                    echo 
    "<p>\n";
                    echo 
    "<table dir='rtl' align='center' cellspacing='5' bgcolor='#e9e9e9' border=0 width='70%'style='font: 8pt verdana, geneva, lucida, arial, helvetica, sans-serif;'>\n";
                    echo 
    "<tr><td align=right>\n";
                    echo 
    "<b>ţÓ˙:</b>\n";
                    echo 
    "<br>".$row["name"]." <br>\n";
                    echo 
    "<b> ˘ň°˝Ý ß: </b>\n";
                    echo 
    "<br>".$row["date"]." <br><br>\n";
                    echo 
    "<b> ń°˛Úň´: </b>\n";
                    echo 
    "<br>".$row["message"]."\n";
                    echo 
    "</tr></td></table>\n";
                    echo 
    "</html>\n";

                }
            }
        } else {
            echo 
    "<font face='Arial' size='2'>An error occured will trying to select the database.</font>\n";
        }
        
    mysql_close ($link);
    ?>
    Returns the next error:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/yazamim/webapps/htdocs/ideas/admin1.php on line 43

    Line 43:
    PHP Code:
    while ($row mysql_fetch_array ($result)) { 
    Can anyone help me?

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    change this line
    PHP Code:
    $result mysql_query ("Select * from GuestBook order by gb_index desc"); 
    to

    PHP Code:
    $result mysql_query ("Select * from GuestBook order by gb_index desc") or die (mysqlL_error()); 
    That error tends to mean there is no data in $result so you could check that my putting this line

    PHP Code:
    print mysql_num_rows($result); 
    just before the while loop

    that won't fix the problem but might help find out what the problem is

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You!
    I have managed to find the problem..
    The table name at the database wasn't correct (case-sensitive)

    Thanks Again

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    That error tends to mean there is no data in $result
    The error means the query failed (syntax error, typo's or incorrect table/column names, no database selected, no connection to database server...) and returned a FALSE value. Executing a mysql function using the FALSE value instead of a resource result is what causes the error. A query that succeeds returns a valid resource result even if the number of rows in the result is zero.

    Executing a mysql_fetch_array($result) on a resource result with zero rows returns a FALSE value. Executing a mysql_num_rows($result) on a resource result with zero rows returns a ZERO value.

    Executing a mysql_fetch_array($result) or a mysql_num_rows($result)following a failed query, results in the error.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •