|
|
#1 (permalink) | |
|
Cass Doesn't Sleep
Seasoned Poster
Joined in Mar 2008
Lives in Michigan
Hosted on SH138
78 posts
Gave thanks: 5
Thanked 6 times
|
PHP Question. Help me out here, folks.
Working on the back side of my site.
Writing the login script for my CMS, and I'm running into a problem. This is the first time that I've worked with PHP on a server that doesn't have REGISTER_GLOBALS turned on, so I'm almost certain it's something to do with the way I'm doing things. I'm sure it's a stupid mistake; one that I'll no doubt slap myself in the forehead for once someone offers a solution. Here's the code in question: Code:
$userName = $_POST['userName'];
$userPass = $_POST['userPass'];
DBConnect("contraba_users");
$sqlCheckUser = mysql_query("SELECT `userID` FROM `users` WHERE `userName` = '$userName' LIMIT 1") or die (mysql_error());
$sqlCheckPass = mysql_query("SELECT `userID` FROM `users` WHERE `userPass` = '$userPass' LIMIT 1") or die(mysql_error());
if(mysql_num_rows($sqlCheckUser == "0") || mysql_num_rows($sqlCheckPass == "0")){
header("Location: ./?stype=error&error=1");
}
Quote:
Any insight would be very welcome.
__________________
rockin' contrabandheart.net on SH138
|
|
|
|
|
|
|
#2 (permalink) | ||
|
URB4N 5K1LLZ
Super #1
Joined in Sep 2005
Lives in Orlando, FL
Hosted on SH63
2,648 posts
Gave thanks: 81
Thanked 127 times
|
Quote:
or Quote:
__________________
Roxanne Surpass Staff Urban Roxy -Personal Blog SH63 - the best darn shared server!
|
||
|
|
|
| This user thanks Roxy for this great post! | cass_is_awesome (March 12th, 2008) |
|
|
#3 (permalink) |
|
Cass Doesn't Sleep
Seasoned Poster
Joined in Mar 2008
Lives in Michigan
Hosted on SH138
78 posts
Gave thanks: 5
Thanked 6 times
|
Roxy: Thanks for the advice.I fixed it. I don't know what was wrong, but as opposed to running a query to check both the password and user name in the DB separately, I just had one query line check both of them in one, like so: Code:
$userName = $_POST['userName'];
$userPass = $_POST['userPass'];
DBConnect("contraba_users");
$sqlCheckUser = mysql_query("SELECT userName,userPass FROM `users` WHERE `userName` = '$userName' AND `userPass` = '" . md5($userPass) . "' LIMIT 1");
__________________
rockin' contrabandheart.net on SH138
Last edited by cass_is_awesome; March 12th, 2008 at 4:26 PM. |
|
|
|
|
|
#4 (permalink) |
|
Surpass Developer
On a golden path...
Joined in Jan 2004
Lives in Florida
Hosted on decc.surpasshosting.com
396 posts
Gave thanks: 10
Thanked 68 times
|
PHP Code:
PHP Code:
PHP Code:
__________________
Mark Surpass Hosting Developer sɹnoʎ uɐɥʇ ɹǝʇʇǝq sı bıs ʎɯ |
|
|
|
| This user thanks Mark for this great post! | cass_is_awesome (March 12th, 2008) |
|
|
#5 (permalink) | |
|
Cass Doesn't Sleep
Seasoned Poster
Joined in Mar 2008
Lives in Michigan
Hosted on SH138
78 posts
Gave thanks: 5
Thanked 6 times
|
Quote:
I did away with that, like I said above, by just doing a user name and password check inside of the query itself. It's the first time I've done that, and it saved me a whole lot of work. The PHP only sets a login cookie if the conditions in the query are met (the username and password must match). Otherwise, it displays an incorrect information error.
__________________
rockin' contrabandheart.net on SH138
|
|
|
|
|
|
|
#6 (permalink) |
|
Surpass Developer
On a golden path...
Joined in Jan 2004
Lives in Florida
Hosted on decc.surpasshosting.com
396 posts
Gave thanks: 10
Thanked 68 times
|
Glad you got it working. Don't forget to sanitize any variables you are putting into an SQL string:
PHP Code:
__________________
Mark Surpass Hosting Developer sɹnoʎ uɐɥʇ ɹǝʇʇǝq sı bıs ʎɯ |
|
|
|
| This user thanks Mark for this great post! | cass_is_awesome (March 12th, 2008) |
|
|
#7 (permalink) |
|
URB4N 5K1LLZ
Super #1
Joined in Sep 2005
Lives in Orlando, FL
Hosted on SH63
2,648 posts
Gave thanks: 81
Thanked 127 times
|
Mark you are a PHP GURU!
__________________
Roxanne Surpass Staff Urban Roxy -Personal Blog SH63 - the best darn shared server!
|
|
|
|
|
|
#8 (permalink) |
|
Surpass Developer
On a golden path...
Joined in Jan 2004
Lives in Florida
Hosted on decc.surpasshosting.com
396 posts
Gave thanks: 10
Thanked 68 times
|
That is true. I also don't like restoring databases
![]() ![]()
__________________
Mark Surpass Hosting Developer sɹnoʎ uɐɥʇ ɹǝʇʇǝq sı bıs ʎɯ |
|
|
|
|
|
#9 (permalink) | |
|
Cass Doesn't Sleep
Seasoned Poster
Joined in Mar 2008
Lives in Michigan
Hosted on SH138
78 posts
Gave thanks: 5
Thanked 6 times
|
Quote:
And that is why I am growing to love this place already.
__________________
rockin' contrabandheart.net on SH138
|
|
|
|
|