
May 2nd, 2002, 01:49 AM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 22,309
Time spent in forums: < 1 sec
Reputation Power: 24
|
|
|
foreach() help
Hey guys..
I'm trying to use a modified version of Matt's tutorial on News Posting Script to make some sort of user verification system.
I just have a problem in the code, it loops the stuff depending on the number of lines in the database file...
here's an example:
http://members.lycos.co.uk/initialdrive/scripts/loopy.php
And here's the script:
php Code:
Original
- php Code |
|
|
|
<? $username = "username"; $pass_enter = "password"; $pass = md5($pass_enter); $double_check = array($username, $pass); // Load User Database File $check = file('userdata.dat'); foreach($check as $element) { $element = trim($element); $user_info = explode("|", $element); if($double_check == $user_info){ echo "<p><b>Username already exists in the database</b>"; } if($double_check != $user_info){ echo "<p>Username does not exist in the database"; } } ?> <body style="font-family: Tahoma; font-size: 8 pt">
The userdata.dat file has 3 lines (3 users with corresponding passwords)
As you can see, it loops 3 times and it prints out the right stuff...I tried using break; in the script but it only evaluated the first line of the database file...
Can anyone clarify how I make the script just print out one line? depending on if the username is found, it'll print "Username Found" and if not it'll print "Username not Found"
Thanks
|