Page 1 of 1

mysql_result()

Posted: Tue Jun 14, 2005 10:36 am
by VikG
Hey this is my first post. Found this site via google.

I am installing a php script that my friend had someone make him.

I have a login form for the admin area. However, when i try to login it will give me the following error:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/dc4u/public_html/control/index.php on line 48

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/dc4u/public_html/control/index.php on line 50
However, i look at the PHP behind this and i see the following (code started from line 40):

Code: Select all

echo($login_screen);
echo("<script>alert('Your session data was not found, please login.');</script>");
session_destroy();
mysql_close;
exit;
}
} else {
$res = mysql_query("select value from admin where field='login'");
$db_login = mysql_result($res, 0);
$res = mysql_query("select value from admin where field='passwd'");
$db_passwd = mysql_result($res, 0);
if ($_SESSION['asess_name'] != $db_login || $_SESSION['asess_passwd'] != md5($db_passwd)) {
echo($login_screen);
echo("<script>alert('Invalid login, please check your admin username and password.');</script>");
session_destroy();
mysql_close;
exit;
}
Can anyone suggest why this is happening?

Posted: Tue Jun 14, 2005 11:44 am
by pickle
Is the connection to the database set up?
Try running the query by itself and see what you get. I think you'll get that error if query returns nothing.

Posted: Tue Jun 14, 2005 2:09 pm
by VikG
I will double check to make sure the database connection is in place.

Posted: Tue Jun 14, 2005 2:14 pm
by VikG
Quite an embarassing mistake. The user was not added to the SQL DB so it was unable to connect.

Apologies for time wasting :oops:

Posted: Tue Jun 14, 2005 2:15 pm
by pickle
Ha - happens to all of us.