473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Loging Script

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
2 1310
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
3
by: MIUSS | last post by:
Hi need an advice, I'm beginner with PHP. I got little problem: I use this solution as login to get administration of my pages: <?php // if authorization isn't done we request it if...
1
by: shiva359 | last post by:
Dear All , will changes done on a table data After a load with nonrecoverable option on a archive loging enabled Database be recorded in logs if we don't do a complete backup ...
3
by: divina11 | last post by:
I'm writting a login script using JavaScript, can someone help with the parts I've commented? Thank you <HTML><HEAD> <TITLE>Login Program</TITLE> </HEAD> <SCRIPT> function validate() {
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.