Trouble with 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
lase
Forum Newbie
Posts: 5
Joined: Thu May 07, 2009 10:05 am

Trouble with mysql_result!

Post by lase »

Okay, I've been working on this for the last 3 hours. :banghead:

I don't know what I'm doing wrong, I'm getting this error when the script is run:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/lasegon/public_html/youscrape/authlib.php on line 64

Here's my sql query along with the code:

Code: Select all

$res =    mysql_query("SELECT password FROM users WHERE username =  '".$uname."'");
            //$resEncrypted = crypt($res,'SHA_512');
            $passEncrypted = crypt($pword, 'whirlpool');
            $row = mysql_result($res, 0);
$pword refers to a $_POST variable. $uname refers to a post variable.

If anyone could tell me whats wrong, thank you SO much.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Trouble with mysql_result!

Post by califdon »

Do yourself a huge favor, so you won't bang your head against the wall for 3 hours again: always make your queries like this:

Code: Select all

$sql="SELECT password FROM users WHERE username = '$uname'";
echo $sql;  // this is for debug, remove this line after it's working
$res=mysql_query($sql) or die(mysql_error());
 
It will tell you what the problem is immediately.

I hope you are sanitizing your POST variables before feeding them to the database!
lase
Forum Newbie
Posts: 5
Joined: Thu May 07, 2009 10:05 am

Re: Trouble with mysql_result!

Post by lase »

Califdon, thank you so^1000 much. I made a very stupid mistake that I seemed to have missed. I forgot to select the database XD. And yes, I have them going through escape stuff, and encryption stuffs before.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Trouble with mysql_result!

Post by califdon »

lase wrote:Califdon, thank you so^1000 much. I made a very stupid mistake that I seemed to have missed. I forgot to select the database XD. And yes, I have them going through escape stuff, and encryption stuffs before.
I'm sure lucky that I never make stupid mistakes . . . hey, that's what error messages are for. Let 'em work for you! Maybe the biggest stupid mistake I made was thinking that it would be fun to be a programmer! :P
Post Reply