[JaxPM] Code Help

CGR Online cgronline at jaxcan.org
Sat Jan 20 17:43:12 CST 2001


I got it....I've attached the file.	
I was trying to use numeric operators w/ strings. I changed from == to eq
and from != to ne.  Thanx



---
Sir Anvil
www.christiangamers.org

On Sat, 20 Jan 2001, CGR Online wrote:

> On the jacksonville-pm-list; Jax.PM'er CGR Online <cgronline at jaxcan.org> wrote -
> 
> UGH. I need help.  Here is a sample of my code. What it is supposed to do
> is this. From a web page (see code belwo) you type in either a mobile
> telephone number or an E-mail address or both. What it is supposed to do
> then is select a random line from a flat file and send it via e-mail to
> either the e-mail address entered by the user or their mobile phone number
> @ptel.net. 
> 
> Okay, so what's wrong is this. The mobile number works fine. Tested many
> times. If you don't type anything in either field, it goes to an error
> with is fine also. However when you put the e-mail address it sill gives
> the same error as though there was no e-mail address given. At the end of
> the error sub code you can see I had it print out the variables to make
> sure they were getting filled and it is!! that's confusing me. So here is
> the HTML
> 
> ---snip---
> <HTML> <TITLE>Send a Verse</TITLE>
> 
> <body bgcolor="black" text="white" vlink="green">
> 
> <CENTER><a href="http://www.christiangamers.org"><IMG
> SRC="http://www.christiangamers.org/goldenic.gif" border=0> click to
> return</a></CENTER> <FORM
> ACTION="http://alpha.jaxcan.org/~cgronline/vs/randv.cgi">
> 
> Enter Your Mobile Number:<input name="mobile"> <BR> or <BR> You can enter
> your e-mail address:<input name="email"> <BR> <input type=submit
> value=Finished> <input type=reset value=Reset>
> 
> <center>The mobile section is for Powertel Users who have Mobile
> E-mail</center>
> ---snip---
> 
> Now here is the perl code
> 
> ---snip---
> #!/usr/bin/perl use CGI;
> use diagnostics;
> use CGI::Carp 'fatalsToBrowser'; 
> 
> $q = new CGI; 
> 
> #$mail=$q->escapeHTML( $q->param('mail'));
> my $mobile=$q->escapeHTML( $q->param('mobile'));
> my $sendmail="/usr/sbin/sendmail";
> my $email=$q->escapeHTML( $q->param('email')); my $blank = ""; 
> 
> #### Randomize the Line ####
> open(FH, "<verse.txt");
> rand($.) < 1 and ($line = $_) while <FH>; close(FH); 
> 
> if ($mobile == $blank) { 
> 	&error;
> 	exit;
> }
> 
> ### Send to Mobile ###
> $sufix="\@ptel.net";
> open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
> print MAIL "To:$mobile$sufix\n";
> print MAIL "Subject:\n";
> print MAIL "$line\n";
> close(MAIL); 
> 
> print "Content-Type: text/html\n\n";
> print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
> print "The following has been sent to your phone.<BR>";
> print "<B>$line<BR></B>";
> print "<FORM><INPUT TYPE=\"BUTTON\" NAME=\"GOBACK\" VALUE=\"BACK\"
> OnClick=\"history.go(-1)\"></FORM><BR>\n"; 
> 
> sub email { 
> ### Send to e-mail ###
> open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
> print MAIL "To: $email\n";
> print MAIL "Subject:\n"; 
> print MAIL "$line\n";
> close(MAIL); 
> 
> print "Content-Type: text/html\n\n";
> print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
> print "The following has been sent to your phone.<BR>";
> print "<B>$line<BR></B>"; print "<FORM><INPUT TYPE=\"BUTTON\"
> NAME=\"GOBACK\" VALUE=\"BACK\" OnClick=\"history.go(-1)\"></FORM><BR>\n";
> }
> 
> sub error {
> if ($email != $blank) {
> 	&email;
> 	exit;
> }
> else {
> print "Content-Type: text/html\n\n";
> print "Sorry, you must enter something for it to work\n";
> print "<BR>Click on the back button<BR>";
> print "m : $mobile<BR>";
> print "e : $email\n";
> }
> }
> ---snip---
> 
> This is the third re-write of the code. The first two handled the if
> statements differently but all had the exact same results. For example
> 
> if (($mobile == $blank) && ($email == $blank)) { &error;  exit;  } elsif
> ($mobile != $blank) 
> 
> and so on and so forth.... 
> 
> Any Idea? HELP ME OBI WAN KANOBI Your my only hope.
> 
> 
> 
> Jax.PM Moderator's Note:
> This message was posted to the Jacksonville Perl Monger's Group listserv.
> The group manager can be reached at -- owner-jacksonville-pm-list at pm.org
> to whom send all praises, complaints, or comments...
> 
-------------- next part --------------
#!/usr/bin/perl
use CGI;
use diagnostics;
use CGI::Carp 'fatalsToBrowser';

$q = new CGI;

#$mail=$q->escapeHTML( $q->param('mail'));
my $mobile=$q->escapeHTML( $q->param('mobile'));
my $sendmail="/usr/sbin/sendmail";
my $email=$q->escapeHTML( $q->param('email'));
my $blank = "";


#### Randomize the Line ####
open(FH, "<verse.txt");
rand($.) < 1 and ($line = $_) while <FH>;
close(FH);


if (($mobile ne $blank) && ($email ne $blank)) {
	&both;
	exit;
}

if ($mobile eq $blank) {
	&error;
	exit;
}
else {
### Send to Mobile ###
$sufix="\@ptel.net";
open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
print MAIL "To: $mobile$sufix\n";
print MAIL "Subject:\n";
print MAIL "$line\n";
close(MAIL);

print "Content-Type: text/html\n\n";
print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
print "The following has been sent to your phone.<BR>";
print "<B>$line<BR></B>";
print "<FORM><INPUT TYPE=\"BUTTON\" NAME=\"GOBACK\" VALUE=\"BACK\"
OnClick=\"history.go(-1)\"></FORM><BR>\n";
exit;
}

sub error {
if ($email eq $blank) {
print "Content-Type: text/html\n\n";
print "Sorry, you must enter something for it to work\n";
print "<BR>Click on the back button<BR>";
print "m : $mobile<BR>";
print "e : $email\n";
}

else {
### Send to e-mail ###
open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
print MAIL "To: $email\n";
print MAIL "Subject:\n";
print MAIL "$line\n";
close(MAIL);

print "Content-Type: text/html\n\n";
print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
print "The following has been sent to your e-mail.<BR>";
print "<B>$line<BR></B>";
print "<FORM><INPUT TYPE=\"BUTTON\" NAME=\"GOBACK\" VALUE=\"BACK\"
OnClick=\"history.go(-1)\"></FORM><BR>\n";
}
}

sub both {
$sufix="\@ptel.net";
open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
print MAIL "To: $email\n";
print MAIL "Cc: $mobile$sufix\n";
print MAIL "Subject:\n";
print MAIL "$line\n";
close(MAIL);

print "Content-Type: text/html\n\n";
print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
print "The following has been sent to your phone and e-mail.<BR>";
print "<B>$line<BR></B>";
print "<FORM><INPUT TYPE=\"BUTTON\" NAME=\"GOBACK\" VALUE=\"BACK\"
OnClick=\"history.go(-1)\"></FORM><BR>\n";

}


More information about the Jacksonville-pm mailing list