PDA

View Full Version : Checking Usernames in a DB file


ACJavascript
11-23-2002, 09:07 PM
Hello All :D,
Heres my problem.
I have a script that creates members with there own usernames.
Now there usernames are written to a .db file.
What i am trying to do but seem to be failing at is to pull the .db file and check it for a username.
Essentialy I want to see if a username some types in has already been taken.

Heres the part of my script that does this.
What ap i doing wrong:(

The below script does an if else structure,, If a username is used it writes to the window saying you have to choose another one.. Else it writes the username to the database.


------------------------------------------

open(Log,"$directoryM/MembersLog.db") || print "Error: Cant open Member database to (read)";
@names = <Log>;
close(Log);
foreach $UName(@names){
($UNames) = split(/\|/,$Uname);
}

if($FORM{'username'} eq "$UNames"){

print "Content-type:text/html\n\n";

print <<UsedName;
<html><head><title>V.R.S.G.C [ USSED USERNAME ] </title></head><body bgColor="black" text="white">
<center><BR>
<font face="verdana,arial" color="red" size=4><b>Error:</b> The Username: $FORM{'username'}. Has already been chosen.<BR>
Please hit back and try again.</font>
If you have any more difficulties please contact support at: <a href="mailto:support@bandit.addr.com">support@bandit.addr.com</a>
<hr width=30>
<sup>Maintained by V.R.S.G.C Member Funtions ver 1.1</sup>
UsedName
exit;
}else{
$username=$FORM{'username'};
open(WriteLog,">>$directoryM/MembersLog.db") || print "Error: Can't open Member database to (write)";

print WriteLog "$username|\n";
close(WriteLog);
&WriteDataAndEmail;
}

___________________


Please help

Thanks in advance!!

crca
11-24-2002, 03:34 AM
I had the same problem!!
Replace::
if($FORM{'username'} eq "$UNames"){

With::
if($FORM{'username'} eq "$UNames\n"){

The only thing is then, you will need to have a new line at the end of t he file.


Hope this helps!

Grizz2
11-24-2002, 06:43 AM
Maybe try this:


# set a found variable
$found = 0;
open(Log,"$directoryM/MembersLog.db") || print "Error: Cant open Member database to (read)";
@names = <Log>;
close(Log);
foreach $UName(@names){
chomp($UName);
($UNames) = split(/\|/,$Uname);
# put the test inside your foreach so you test each $UNames
if($FORM{'username'} eq "$UNames"){$found = 1}
}
# then check the found variable to see what to do
if($found == 1){
username taken;
}else{
username not taken;
}

Grizz

ACJavascript
11-24-2002, 04:44 PM
Both great ideas,, i am trying them out NOW!
I sure hope one of them work lol :D

ACJavascript
11-24-2002, 05:21 PM
Hi again i am getting the same problems and 1 other.

It is not checking the db for the usernames it seems to be skiping right over it and just writting the username to the db file. Now what is really weird is that when i opened the db file to write it like so >Write!
And then use the same username to add an acount it says that that username has already been used.
But when I open it to >>Append!
It doesn't work,,, heres the code now this has Grizz and Crca
additions.

Any help is most appreciated. :)
Could it be that mabye the $directoryM scalar is set to the actual directory path instead of the URL?
______________

$found=0;
open(Log,"$directoryM/MembersLog.db") || print "Error: Cant open Member database to (read)";
@names = <Log>;
close(Log);
foreach $UName (@names){
chomp($UName);
if($FORM{'username'} eq "$UName\n"){
$found=1;
}
}

if(found == 1){
&UsedUsername;
}else{
$username=$FORM{'username'};
open(WriteLog,">>$directoryM/MembersLog.db") || print "Error: Can't open Member database to (write)";

print WriteLog "$username\n";
close(WriteLog);
&WriteDataAndEmail;
}

__________

PLease help :)

Thanks in advance!!!!!!!!!!!

P.S I really need this script

Grizz2
11-24-2002, 07:15 PM
Chomp removes the line ending characters so you wouldn't need the \n in the comparison below. But since you were using a pipe as a seperator
you need to use that in your comparison or remove it.
Example:
foreach $UName (@names){ $UName looks like -- "username|\n"
chomp($UName); now $UName looks like -- "username|"
###
if(found == 1){ This may be a typo but dont forget the $ on the found variable

$found=0;
open(Log,"$directoryM/MembersLog.db") || print "Error: Cant open Member database to (read)";
@names = <Log>;
close(Log);
foreach $UName (@names){
chomp($UName);
if($FORM{'username'} eq "$UName\n"){
#if you are still using the pipe use this
#if($FORM{'username'} eq "$UName|"){
#if you are not using the pipe use this
#if($FORM{'username'} eq "$UName"){
$found=1;
}
}

if(found == 1){
&UsedUsername;
}else{

Grizz

ACJavascript
11-24-2002, 10:11 PM
THANK YOU SO MUCH GRIZZ!!!!!!!!!!!!!!!
That so called typo LOL was the problem... Thanks for pointing that out.... It works wonderfuly now,, thank you so much..:D:D:D