Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2002, 04:59 AM   PM User | #1
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
Error with making login page...!

Hello, I'm fairly new to PHP (about 4 months using it).

I'm trying to make a script for loging in, but I seem to have a error in my scripting. can you please help?

All I get is "We're sorry, your username does not appear to be in our database." even when the username is in the database.

Here's my Code:

PHP Code:
<?php

// MySQL User Login, Copyright 2002 Acorn Webs. All Rights Reserved.
//
// This Script is for Acorn Webs use ONLY!
// Includes Acorn Webs Clients.

// Include Files

require("includes/mysql.inc");

// End of Include Files
// query commands

mysql_select_db("phpbb2"$linkID) or die(mysql_error());

$resultID mysql_query("SELECT user_id FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

// End of query commands
// Check Username

$num_rows mysql_num_rows($resultID); 
$row mysql_fetch_array($resultID); 
$user_id $row[0]; 

if (
$user_id == "") {
    print 
"We're sorry, your username does not appear to be in our database.";
}
else {
// End of Check Username
// query and other commands

    
$resultID mysql_query("SELECT user_password FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

    
$encryptedpassword md5($password);
    
    
$row mysql_fetch_array($resultID); 
    
$passwordfromdb $row[0];
// End of query commands
// Check Password

    
if ($encryptedpassword == $passwordfromdb) {
        print 
"We're sorry, your password or username is incorrect.";
    }
    else {
        print 
"login currect";
    }
}

// End of Check Password

mysql_close($linkID);

?>
I'm sure it's something so simple but I can't seem to find it.
Thanks.
EthanX is offline   Reply With Quote
Old 07-26-2002, 01:28 PM   PM User | #2
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
From a first look, your code looks well done and should work alright. From the output it generates, you know already that the problem must lie somewhere in these lines:

PHP Code:
$row mysql_fetch_array($resultID); 
$user_id $row[0]; 

if (
$user_id == "") { 
Which further indicates, that there is either no appropriate data in the database or the query was somehow malformed. I would suggest narrowing the problem by trying to run this adjusted code:

PHP Code:
mysql_select_db("phpbb2"$linkID) or die(mysql_error());

$sql "SELECT user_id FROM phpbb_users WHERE username = '$username'";

// trace the contents of $sql
echo $sql "<br>";

$resultID mysql_query($sql$linkID) or die(mysql_error());

// End of query commands
// Check Username

$num_rows mysql_num_rows($resultID); 
$row mysql_fetch_array($resultID); 

echo 
"<pre>";
var_dump($row);
echo 
"</pre>";

$user_id $row[0]; 

echo 
"<br>" $user_id
This should show you what your query acutally consisted of. Also, all returned values from the query will be shown. Perhaps it's just a typo, but I could also think that you're expecting form variables to extracted automagically by the register_globals option. In modern versions of PHP, this feature is disabled by default. Maybe your provider did an upgrade and failed to inform you. In this case, you could try with

$_POST["username"]

to get the values of the form variable instead of just writing $username.

Hope that helps.
mordred is offline   Reply With Quote
Old 07-26-2002, 05:40 PM   PM User | #3
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
okay, thanks but I found my problem after trying some more test.
I had a file (mysql.inc) with $username and $password varable in it for the MySQL username and password, so I changed it's name and it works.. kinda..

Now even if I don't put a password in it logs in.
As you can see I'm trying to use a PHPBB database, and it should work, but it's not checking password.

here's the code (same as before):

PHP Code:
<?php

// MySQL User Login, Copyright 2002 Acorn Webs. All Rights Reserved.
//
// This Script is for Acorn Webs use ONLY!
// Includes Acorn Webs Clients.

// Include Files

require("includes/mysql.inc");

// End of Include Files
// query commands

mysql_select_db("phpbb2"$linkID) or die(mysql_error());
$resultID mysql_query("SELECT user_id FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

// End of query commands
// Check Username

$num_rows mysql_num_rows($resultID); 
$row mysql_fetch_array($resultID); 
$user_id $row[0]; 

if (
$user_id == "") {
    print 
"We're sorry, your username does not appear to be in our database.";
}
else {
// End ofCheck Username
// query commands

    
$resultID mysql_query("SELECT user_password FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

    
$encryptedpassword md5($password);
    
    
$row mysql_fetch_array($resultID); 
    
$passwordfromdb $row[0];
// End of query commands
// Check Password

    
if ($encryptedpassword !== $passwordfromdb) {
        print 
"We're sorry, your password or username is incorrect.";
    }
    else {
        print 
"login currect";
    }
}

// End of Check Password

mysql_close($linkID);

?>
*BTW, It's my server

Last edited by EthanX; 07-26-2002 at 06:02 PM..
EthanX is offline   Reply With Quote
Old 07-27-2002, 04:56 PM   PM User | #4
Cloudski
Regular Coder

 
Join Date: Jul 2002
Location: U.S. (Wish Japan though)
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Cloudski is an unknown quantity at this point
Yuo have 1 too many = signs... change:
PHP Code:
// Check Password

    
if ($encryptedpassword !== $passwordfromdb) {
        print 
"We're sorry, your password or username is incorrect.";
    }
    else {
        print 
"login currect";
    }
}

// End of Check Password 
To:
PHP Code:
// Check Password

    
if ($encryptedpassword != $passwordfromdb) {
        print 
"We're sorry, your password or username is incorrect.";
    }
    else {
        print 
"login currect";
    }
}

// End of Check Password 
Cloudski is offline   Reply With Quote
Old 07-27-2002, 05:00 PM   PM User | #5
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
Hmmm so simple.... but.. wait.. didn't work
still getting "We're sorry, your password or username is incorrect." and I know my password is currect.

So what's the problem??
EthanX is offline   Reply With Quote
Old 07-27-2002, 05:04 PM   PM User | #6
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
oh man.. I feel so stupid

I put !== back, then I decided to check my form.. and I had the password feild wrong!... gosh
Sorry to wast anyones time.. seems my code was fine all the way.. all but my stupid form.

Thanks anyways.
EthanX is offline   Reply With Quote
Old 07-27-2002, 05:06 PM   PM User | #7
Cloudski
Regular Coder

 
Join Date: Jul 2002
Location: U.S. (Wish Japan though)
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Cloudski is an unknown quantity at this point
Hmm... ok, uh...

I think the error is in the declaration of $passwordfromdb ...

Try changing:
PHP Code:
$row mysql_fetch_array($resultID); 
    
$passwordfromdb $row[0]; 
To:
PHP Code:
$passwordfromdb mysql_fetch_array($resultID); 
Hope that works
Cloudski is offline   Reply With Quote
Old 07-27-2002, 05:07 PM   PM User | #8
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
/\ Read Previous post I made /\
It's working now.. my code unchanged from my first post.
It was my form. Sorry for the troble.
EthanX is offline   Reply With Quote
Old 07-27-2002, 05:10 PM   PM User | #9
Cloudski
Regular Coder

 
Join Date: Jul 2002
Location: U.S. (Wish Japan though)
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Cloudski is an unknown quantity at this point
Lol.. I made my post about same time you made yours... and was no problem I enjoyed working around with it anyways... I am finally learning some MySQL stuff and more PHP
Cloudski is offline   Reply With Quote
Old 07-27-2002, 05:11 PM   PM User | #10
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
Yeah, MySQL isn't hard to learn. PHP is prety simple too.
Thanks once again for you time messing with my junk codin
If you ever need anything just ask.. (I might help )
(I sell hosting )
EthanX is offline   Reply With Quote
Old 07-27-2002, 05:14 PM   PM User | #11
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
BTW, !== is currect. !== (Noy Identical to) != (Not equal to)
EthanX is offline   Reply With Quote
Old 07-27-2002, 05:15 PM   PM User | #12
Cloudski
Regular Coder

 
Join Date: Jul 2002
Location: U.S. (Wish Japan though)
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Cloudski is an unknown quantity at this point
Ah, ok thanks... I only learned C++, and in that you used !=...
Cloudski is offline   Reply With Quote
Old 07-27-2002, 05:16 PM   PM User | #13
EthanX
New Coder

 
Join Date: Jul 2002
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
EthanX is an unknown quantity at this point
Okay, cool.. that's one of the langues I'll learn later.
EthanX is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:09 AM.


Advertisement
Log in to turn off these ads.