...

View Full Version : Error with making login page...!



EthanX
07-26-2002, 04:59 AM
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

// 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.

mordred
07-26-2002, 01:28 PM
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:



$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:



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.

EthanX
07-26-2002, 05:40 PM
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

// 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 :cool:

Cloudski
07-27-2002, 04:56 PM
Yuo have 1 too many = signs... change:


// Check Password

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

// End of Check Password


To:


// Check Password

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

// End of Check Password

EthanX
07-27-2002, 05:00 PM
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
07-27-2002, 05:04 PM
oh man.. I feel so stupid :( :rolleyes:

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

Thanks anyways.

Cloudski
07-27-2002, 05:06 PM
Hmm... ok, uh...

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

Try changing:


$row = mysql_fetch_array($resultID);
$passwordfromdb = $row[0];


To:


$passwordfromdb = mysql_fetch_array($resultID);


Hope that works :thumbsup:

EthanX
07-27-2002, 05:07 PM
/\ Read Previous post I made /\
It's working now.. my code unchanged from my first post.
It was my form. Sorry for the troble.

Cloudski
07-27-2002, 05:10 PM
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 :D

EthanX
07-27-2002, 05:11 PM
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
07-27-2002, 05:14 PM
BTW, !== is currect. !== (Noy Identical to) != (Not equal to)

Cloudski
07-27-2002, 05:15 PM
Ah, ok thanks... I only learned C++, and in that you used !=...

EthanX
07-27-2002, 05:16 PM
Okay, cool.. that's one of the langues I'll learn later.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum