ljcmm
07-31-2005, 12:07 PM
Hello, our site is giving this error on user login:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in (path omitted) on line 143
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in (path omitted) on line 150
Our programmer is unavailable - is this something I can fix myself or get help with asap?
Thank you!
You should rename that file to .phps and post the url to it.
Kijit Solutions
07-31-2005, 12:41 PM
There's probably no results from the previous mysql_query select. Possibly something wrong with your database, or how you're selecting it.
I can't really help out without any snippit of code.
ljcmm
07-31-2005, 12:47 PM
what should I snip for you to look at? Thanks.
ljcmm
07-31-2005, 12:51 PM
Here's line 140 - 150:
<?
$sql = "SELECT * FROM mm_newsletter_users WHERE user_id='$mm_id'";
$result = mysql_query ($sql);
while ($row = mysql_fetch_array ($result)) {
$newsletters_active [$row ["newsletter_id"]] = "Y";
}
$sql = "SELECT * FROM mm_newsletters ORDER BY newsletter_id";
$result = mysql_query ($sql);
while ($row = mysql_fetch_array ($result)) {
?>
zoldar
07-31-2005, 04:46 PM
If tables mm_newsletters and mm_newsletter_users are empty, it's correct behaviour.
To avoid displaying such warning you should change the following:
<?
$sql = "SELECT * FROM mm_newsletter_users WHERE user_id='$mm_id'";
if($result = mysql_query ($sql)) {
while ($row = mysql_fetch_array ($result)) {
$newsletters_active [$row ["newsletter_id"]] = "Y";
}
}
$sql = "SELECT * FROM mm_newsletters ORDER BY newsletter_id";
if ($result = mysql_query ($sql)) {
while ($row = mysql_fetch_array ($result)) {
..
..
..
} // end of while loop
}
?>
zoldar
07-31-2005, 04:51 PM
It would be also better if you've turned off displaying errors directly on page if it's production environment - it can give sometimes valuable information about php code and/or database structure to potential hackers.
You can do this in two ways:
- Put 'ini_set('display_errors','0');' somewhere at the beginning of every php script
- Set 'display_errors = Off' in php.ini and restart/reload webserver
fastduke
07-31-2005, 07:01 PM
Originally posted by zoldar
It would be also better if you've turned off displaying errors directly on page if it's production environment - it can give sometimes valuable information about php code and/or database structure to potential hackers.
You can do this in two ways:
- Put 'ini_set('display_errors','0');' somewhere at the beginning of every php script
- Set 'display_errors = Off' in php.ini and restart/reload webserver
or simply put this in the script
error_reporting(0);
and no need to restart the webserver :)
zoldar
07-31-2005, 08:08 PM
Yes, but I'm not sure if it doesn't turn off logging errors to webserver's logs too... there still should be some way of diagnosing problems
azizny
07-31-2005, 09:43 PM
Just add the "@" sign --> @mysql_fetch_array
it should work fine...
if the database is not empty, then you might not be connected to the database..
Peace,
yktan
08-05-2005, 02:08 AM
One more thing you can do is to put a statement like this:
echo "SELECT * FROM mm_newsletter_users WHERE user_id='$mm_id'";
before the:
$sql = "SELECT * FROM mm_newsletter_users WHERE user_id='$mm_id'";
To get the querystring that is being used to access your database. Then you can manually go to your database and run the statement to see if it is returning a result.
Placing a @ infront of any statement can suppress the error from being thrown but it might cause undesirable results (for the script). Best to ask your programmer to do a better job at ensuring that all possible errors are handled.
nulled
08-07-2005, 02:09 AM
You have MANY problems with your current PHP code.
First off.. do not use short php tags ( i.e <? use <?php instead as this may conflict with XML which also uses <? )
Secondly, you need to create a connection to a Database BEFORE you try to do any mysql_query() calls!
The reason you get invalid resource errors is because it is just that! AN INVALID resource... use mysql_connect() www.php.net and read up on php/mysql