Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filtering information 2

Status
Not open for further replies.

Moooink

Technical User
Feb 22, 2002
48
US
I have a database of people and e-mail address collected into a simple text file in the form: $name~|~$email~|~ simply put. in order for someone to be e-mailed the password for a specific section of the site, they type their e-mail into a form and it searches through the text file through each e-mail and if it finds that e-mail, it sends the e-mail the password. The only problem i am having is Capitalization is preventing this from working. how do i filter the e-mails in the text file so that they are all lowercase, and also filter the field that the user types their e-mail in to recieve the password? sorry for my confusing explanation, but can anyone help? thanks, Nic
 
You can make the form data lowercase:

$form_email = (lc(param('email')));

There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
It's not a subroutine. You said you need to get the info from a form. I used CGI.pm to get the data from the HTML form like this:

#!/usr/bin/perl -w

use CGI;
use CGI qw:)all);

print header;

$form_email = (lc(param('email')));

print &quot;Checking for email: $form_email<br>&quot;;

The lc function will lowercase them all. You can also try the following:

$db = &quot;db.txt&quot;;

open(FILE, &quot;$db&quot;);
@data = <FILE>;
close(FILE);

foreach (@data)
{
chomp($_);
($name,$email)=split(/\~/,$_);

if ($form_email =~/$email/i) {
print &quot;$email<br>&quot;;
}else{
print &quot;Invalid Email&quot;;
}
}

The i function will ignore case. I haven't tested the code listed above, but it should work. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
i can't figure out how to implement these into my script...here are example from each submit sub: this is to submit each name\e-mail to the database, there is another script that checks the valid e-mail from the database and sends if it is found in the db

# sub - submit
sub submit {
### staff
if ($FORM{'form'} eq &quot;staff&quot;) {
# validate
if ($FORM{'position'} eq &quot;&quot;) {&error(&quot;Postion field was left blank. Please hit back and complete the form.&quot;);}
if ($FORM{'name'} eq &quot;&quot;) {&error(&quot;Name field was left blank. Please hit back and complete the form.&quot;);}
# open staff.txt for editing
open (STAFF,&quot;>>$filedir/staff.txt&quot;) || &error(&quot;Can't Open staff.txt $!\n&quot;);
# staff printing
print STAFF &quot;$FORM{'name'}~|~$FORM{'position'}~|~$FORM{'mail'}~|~\n&quot;;
close(STAFF);
}





# editsubmit sub
sub editsubmit {
if ($FORM{'form'} eq &quot;staff&quot;) {
@varkeys = keys (%FORM);
foreach $line(@varkeys) {
unless ($line eq &quot;action&quot; || $line eq &quot;form&quot; || $line eq &quot;$tempnum|del&quot;) {
($tempnum, $varname) = split(/\|/, $line);
if ($varname eq &quot;name&quot;) {
$del = &quot;$tempnum&quot;.&quot;|&quot;.&quot;del&quot;;
$name = &quot;$tempnum&quot;.&quot;|&quot;.&quot;name&quot;;
$position = &quot;$tempnum&quot;.&quot;|&quot;.&quot;position&quot;;
$mail = &quot;$tempnum&quot;.&quot;|&quot;.&quot;mail&quot;;
unless ($FORM{&quot;$del&quot;} eq &quot;yes&quot;) {
$list[$tempnum] = &quot;$FORM{$name}~|~$FORM{$position}~|~$FORM{$mail}~|~\n&quot;;
}
}
}
}
open (STAFF,&quot;>$filedir/staff.txt&quot;) || &error(&quot;Can't Open staff.txt $!\n&quot;);
print STAFF &quot;@list&quot;;
close(STAFF);
}



 
You said &quot;in order for someone to be e-mailed the password for a specific section of the site, they type their e-mail into a form and it searches through the text file through each e-mail and if it finds that e-mail, it sends the e-mail the password.&quot;


Where's the section that will send the password to the email they provide on the form? Should be something like this:

foreach (@data)
{
chomp($_);
($name,$email)=split(/\~/,$_);

if ($form_email =~/$email/i) {
&send_mail;
}else{
print &quot;Invalid Email&quot;;
}
} There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
this is the other script which takes the e-mail from html form and puts it into $toemail...then searches through multiple databases to find the email...if it finds it, it sets $mailfound to 1...then it prints if mailfound=1

$toemail = $FORM{'TOEMAIL'};
$mailfound = 0;
##########################################
<---------------begin 1 db
open (STUDENTS,&quot;$filedir/students.txt&quot;) || &error(&quot;Can't Open students.txt $!\n&quot;);
@students = <STUDENTS>;
close(STUDENTS);
foreach $line(@students) {
($lname, $fname, $grade, $instrument, $mail, $blank) = split(/\~\|~/, $line);
if ($mail eq $toemail) {
$mailfound = 1;
}
}
<-----------------------end 1 db




if ($mailfound eq &quot;1&quot;) {
&mail (&quot;$toemail&quot;, &quot;$fromemail&quot;, &quot;$subject&quot;);
else {
print fail..etc..
}
 
it be if ($mail eq /$toemail/i) {$mailfound = 1}? for each db it searched through?
 
Try this:

open (STUDENTS,&quot;$filedir/students.txt&quot;) || &error(&quot;Can't Open students.txt $!\n&quot;);
@students = <STUDENTS>;
close(STUDENTS);
foreach $line(@students) {
($lname, $fname, $grade, $instrument, $mail, $blank) = split(/\~\|~/, $line);
if ($toemail=~/$mail/i) {
$mailfound = 1;
}
}

Now it will ignore if it's capitalized and send the mail. So, me@host.com and ME@HOST.COM is same. This is what you wanted, right? There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
ok but what if the user types Me@Host.com into the html form....then it searches and only finds me@host.com? is that what it will do?
 
lol i finnaly registered for this site =) technical user~
 
Yep, that is correct. You can also lowercase the $toemail variable like this:

$toemail = lc($FORM{'TOEMAIL'});

So, if somebody entered &quot;ME@HOST.COM&quot;, it will check to see if &quot;me@host.com&quot; exist.

There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
alright now the only problem is, it sends the e-mail to anyone who types their e-mail in....
 
Try this:

open (STUDENTS,&quot;$filedir/students.txt&quot;) || &error(&quot;Can't Open students.txt $!\n&quot;);
@students = <STUDENTS>;
close(STUDENTS);
foreach $line(@students) {
($lname, $fname, $grade, $instrument, $mail, $blank) = split(/\~\|~/, $line);
if ($toemail=~/$mail/i) {
&mail (&quot;$toemail&quot;, &quot;$fromemail&quot;, &quot;$subject&quot;);
}else{
print &quot;Invalid User&quot;;
}
}

It should work. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
but there is more then one db that it has to check...that's why there's a mailfound=0 or 1
 
Hmm... here's my last try:

open (STUDENTS,&quot;$filedir/students.txt&quot;) || &error(&quot;Can't Open students.txt $!\n&quot;);
@students = <STUDENTS>;
close(STUDENTS);
foreach $line(@students) {
($lname, $fname, $grade, $instrument, $mail, $blank) = split(/\~\|~/, $line);
if ($toemail =~/$mail/i) {
$mailfound = 1;
}else{
print &quot;Invalid User&quot;;
}
}

Take Out the $toemail = lc($FORM{'TOEMAIL'}); if you have that. Just put that like: $toemail = $FORM{'TOEMAIL'}; There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
i took out the initial lc($FORm but it still sends the e-mail to any e-mail typed in
 
Any luck? Hopes someone else could help us out with this. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Sorry Moooink, but i'm stuck :( There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Even though I do have a tip. Why don't you try and stick to your orginal code and change and replace only the $toemail variable:

$toemail = lc($FORM{'TOEMAIL'};

$mailfound = 0;
##########################################
<---------------begin 1 db
open (STUDENTS,&quot;$filedir/students.txt&quot;) || &error(&quot;Can't Open students.txt $!\n&quot;);
@students = <STUDENTS>;
close(STUDENTS);
foreach $line(@students) {
($lname, $fname, $grade, $instrument, $mail, $blank) = split(/\~\|~/, $line);
if ($mail eq $toemail) {
$mailfound = 1;
}
}
There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top