mysql_result()

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
VikG
Forum Newbie
Posts: 3
Joined: Tue Jun 14, 2005 10:29 am

mysql_result()

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
VikG
Forum Newbie
Posts: 3
Joined: Tue Jun 14, 2005 10:29 am

Post by VikG »

I will double check to make sure the database connection is in place.
VikG
Forum Newbie
Posts: 3
Joined: Tue Jun 14, 2005 10:29 am

Post 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:
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ha - happens to all of us.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply