The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Login Function Stopped Working
Discuss Login Function Stopped Working in the PHP Development forum on Dev Shed. Login Function Stopped Working PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 4th, 2013, 03:26 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 64
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
|
|
|
Login Function Stopped Working
Everything worked great on wamp, but when I uploaded my files to a live server i'm getting the following error. I don't see where or how it should be expecting a second parameter.
Warning: mysql_result() expects parameter 1 to be resource, boolean given
PHP Code:
function login($username, $password){
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = sanitize($password);
return (mysql_result(mysql_query("SELECT COUNT(`ID`) FROM `members` WHERE `username` = '$username' AND `password` = pwdencrypt('$password')"))==1) ? $user_id : false;
}
|

January 4th, 2013, 03:42 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 64
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
|
|
SOLVED
PHP Code:
return (mysql_result(mysql_query("SELECT COUNT(`ID`) FROM `members` WHERE `username` = '$username' AND `password` = 'pwdencrypt($password)'"), 0)==1) ? $user_id : false;
|

January 4th, 2013, 03:43 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Uh no, not solved. At least I hope not: you're comparing the password against the string "pwdencrypt(password)", not the actual hashed/encrypted password.
|

January 4th, 2013, 03:46 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 64
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by requinix Uh no, not solved. At least I hope not: you're comparing the password against the string "pwdencrypt(password)", not the actual hashed/encrypted password. |
Crap you're right thanks for pointing this out, gotta try to fix this.
|

January 4th, 2013, 04:28 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|

January 4th, 2013, 04:38 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 64
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by requinix |
pwdencrypt worked on wamp, and it did compare the password to the encrypted password at the time.
The problem I'm having now is that mysql_result is expecting two parameters. The "0" in:
PHP Code:
pwdencrypt('$password')"), 0)==1)
Seems to bypass the need for a password altogether. As long as a registered username is entered the user is logged in.
No "0" produces the error:
Warning: mysql_result() expects at least 2 parameters, 1 given
So far any other values I have tried have also produced errors. Any help would be appreciated this is pretty frustrating. I did test this without using an encrypted password an I'm still having the same issue.
|

January 4th, 2013, 05:29 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 64
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
|
|
All good now
PHP Code:
return (mysql_result(mysql_query("SELECT `username` FROM `members` WHERE `username` = '$username' AND `password` = password('$password')"),0)==1) ? $user_id : false;
|

January 4th, 2013, 05:39 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Don't have a GTalk, just the three in my profile (of which I'm only watching one right now).
So all taken care of then?
|

January 4th, 2013, 05:44 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 64
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by requinix Don't have a GTalk, just the three in my profile (of which I'm only watching one right now).
So all taken care of then? |
Yeah all set thanks.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|