By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

Loging Script

P: n/a
It seems there is something wrong with my script for the reason that
it always returns, UserName NOT found . I know it connects to the db
fine because I don't get a error. So just been trying to figure out
what's wrong. I am using PEAR btw.

Pastebin: http://pastebin.ca/360410
<?PHP

require 'DB.php';
$db = DB::connect('mysql://lol:lol@localhost/user');

if (DB::isError($db)) {die('ERROR{1}: ' . $db-
>getMessage()); }else{print "We connected";}
$user = $_POST['user'];
$password = md5($_POST['password']);
$password2 = md5($_POST['password2']);

$sql = check();

function check()
{
global $db;
global $user;
$rows = $db->getAll('SELECT user_name FROM user');
if (DB::isError($db)) {die('ERROR{2}: ' . $db->getMessage());}

if($user){
if(array_key_exists("$user", $rows)){print "<p><b>UserName
AcceptED</b>";}else{print "<p><b>UserName NOT found</b>";}

}else{print "<p>no username was typed";}

}

?>

Feb 17 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
phyburn wrote:
It seems there is something wrong with my script for the reason that
it always returns, UserName NOT found . I know it connects to the db
fine because I don't get a error. So just been trying to figure out
what's wrong. I am using PEAR btw.
By the time it got to me this had some very unusual formatting - I'd
recommend sticking to the PEAR style guidelines, particularly when posting
to newsgroups.
if(array_key_exists("$user", $rows)){
print "<p><b>UserName AcceptED</b>";
You should be looking for a value, not a key - and getAll returns a nested
array - i.e. somewhere there should be...

$rows[$row_number]['username']==$user

But really you should be checking this in the SQL - not loading a list of
all users then checking in PHP.

C.
Feb 17 '07 #2

P: n/a
Rik
On Sat, 17 Feb 2007 14:13:22 +0100, phyburn <ph*****@gmail.comwrote:
It seems there is something wrong with my script for the reason that
it always returns, UserName NOT found . I know it connects to the db
fine because I don't get a error. So just been trying to figure out
what's wrong. I am using PEAR btw.

Pastebin: http://pastebin.ca/360410
<?PHP

require 'DB.php';
$db = DB::connect('mysql://lol:lol@localhost/user');

if (DB::isError($db)) {die('ERROR{1}: ' . $db-
>getMessage()); }else{print "We connected";}

$user = $_POST['user'];
$password = md5($_POST['password']);
$password2 = md5($_POST['password2']);

$sql = check();

function check()
{
global $db;
global $user;
$rows = $db->getAll('SELECT user_name FROM user');
if (DB::isError($db)) {die('ERROR{2}: ' . $db->getMessage());}
Untested, I seldomly use PEAR::DB:

$stmt = $db->prepare('SELECT user_name, password FROM user WHERE user_name
= ?');
$result = $db->execute($stmt,$user);
if($result->numRows()!=1) die('Username not found or multiple users with
the same name.');
--
Rik Wasmus
Feb 17 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.