Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2007, 11:17 AM   PM User | #1
Penguin
New to the CF scene

 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Penguin is an unknown quantity at this point
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?
Penguin is offline   Reply With Quote
Old 01-04-2007, 11:21 AM   PM User | #2
MRMAN
Regular Coder

 
Join Date: Jan 2006
Location: Preston, Lancashire, England
Posts: 285
Thanks: 0
Thanked 0 Times in 0 Posts
MRMAN is an unknown quantity at this point
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
MRMAN is offline   Reply With Quote
Old 01-04-2007, 11:33 AM   PM User | #3
Penguin
New to the CF scene

 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Penguin is an unknown quantity at this point
Thank You!
I have managed to find the problem..
The table name at the database wasn't correct (case-sensitive)

Thanks Again
Penguin is offline   Reply With Quote
Old 01-04-2007, 02:38 PM   PM User | #4
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,712
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Quote:
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.
CFMaBiSmAd is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:40 PM.


Advertisement
Log in to turn off these ads.