dave,
below is a snipet of the code. the most relavant part. when i enter some
bad data in or mysql has problems, it should go to error_handler() at the
bottom of my script. well it does, then it returns unless i put an exit at
the end of error_handler.
----------------------------------------------------------------------------
-------------------------------
#!/usr/bin/perl -wT
use CGI::Fast;
$CGI::DISABLE_UPLOADS = 1; # Disable uploads
$CGI::POST_MAX = 512 * 1024; # limit posts to 512K max
use DBI;
use HTML::Template;
while ($q = new CGI::Fast) {
print_firstpage() if (!$q->param());
print_search_by_listing() if ($q->param("by_listing"));
print_search_by_state() if ($q->param("search_by_state"));
print_firstpage() if ($q->param("done"));
sub print_firstpage {
my $template = HTML::Template->new(filename => 'myindex-front.html' );
print $q->header();
print $template->output();
}
sub print_search_by_listing {
my $first = $q->param("listing");
if ((defined($first)) && ($first =~ /^[0-9]+$/)){
my $dbh = DBI->connect("DBI:mysql:database=test","myuser",
"mypassword",{RaiseError=>0,PrintError=>0}) or error_handler(2);
$quoted_first = $dbh->quote($first);
my $sth = $dbh->prepare("select * from usernames where user =
$quoted_first") or error_handler(2);
$sth->execute() or error_handler(2);
$refer = $sth->fetchall_arrayref([
0,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 ]) or
error_handler(1,$first);
$sth->finish;
$dbh -> disconnect;
if (@$refer) {
print_table($refer); ## jump to sub to print table ##
} else {
error_handler(1,$first);
}
} elsif ((defined($first)) && ($first =~ /\D+/)) {
error_handler(1,$first);
}
}
sub print_search_by_state {
my $template = HTML::Template->new(filename => 'myindex-by-state-final.html'
);
my $dbh = DBI->connect("DBI:mysql:database=test","myuser",
"mypassword",{RaiseError=>0,PrintError=>0}) or error_handler(2);
$the_state = $q->param("by_state");
$the_type = $q->param("types");
$lo = $q->param("lo"); #used for keeping track of count.
if (($q->param("sort_by") eq "location") || ($q->param("sort_by") eq
"city")){
$the_sort_criteria = "city";
}
if (($q->param("sort_by") eq "price") || ($q->param("sort_by") eq "ask")){
$the_sort_criteria = "ask + 0";
}
if (($q->param("sort_by") eq "bedrooms") || ($q->param("sort_by") eq
"bed")){
$the_sort_criteria = "bed";
}
if ($the_state =~ /[\!\@\#\%\^\&\*\(\)\{\}\[\]\:\;\"\'\?\<\>\/\~\`\|]/)
{
error_handler(1,$the_state);
}
if ($the_type =~ /[\!\@\#\%\^\&\*\(\)\{\}\[\]\:\;\"\'\?\<\>\~\`\|]/) {
error_handler(1,$the_type);
}
if ($the_sort_criteria =~
/[\!\@\#\$\%\^\&\*\(\)\{\}\[\]\:\;\"\'\?\<\>\,\/\~\`\|]/) {
error_handler(1,$the_sort_criteria);
}
if (($lo) && ($lo =~
/[\!\@\#\$\%\^\&\*\(\)\{\}\[\]\:\;\"\'\?\<\>\,\/\~\`\|]/)) {
error_handler(1,$lo);
}
$quoted_the_state = $dbh->quote($the_state);
$quoted_the_type = $dbh->quote($the_type);
if ($the_type =~ /All-Types/) {
$sth1 = $dbh->prepare("select count(*) from usernames where state =
$quoted_the_state") or error_handler(2);
}
if ($the_type !~ /All-Types/) {
$sth1 = $dbh->prepare("select count(*) from usernames where state =
$quoted_the_state and type = $quoted_the_type") or error_handler(2);
}
$sth1->execute()or die "died on executing";# or error_handler(2);
my @rows = $sth1->fetchrow_array;
$sth1->finish;
....
sub error_handler {
$template_error = HTML::Template->new(filename => 'error.html' );
$code = shift;
$error_data = shift;
$error_data2 = shift;
if ($code == 1) {
$template_error->param( THE_DATA => $error_data );
$template_error->param( NO_RECORD => 1 );
}
if ($code == 2) {
$template_error->param( DATABASE_ERROR => 1 );
}
if ($code == 3) { # this handles the type and state error from line 139
$template_error->param( NO_STATED_TYPE => 1 );
$template_error->param( THE_STATED => $error_data );
$template_error->param( THE_TYPED => $error_data2 );
}
print $q->header();
print $template_error->output();
exit; ### how can i not "exit" and still stop the processing?
}
}
----------------------------------------------------------------------------
-------------------------------
> -----Original Message-----
> From: David Gray [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 23, 2002 3:51 PM
> To: [EMAIL PROTECTED]; 'Boex,Matthew W.'
> Subject: RE: exiting correctly
>
>
> > i have a regex that checks for a string in a param, if not
> > found, it should jump to an error subroutine. from there, i
> > print out "this is an error", etc. after that prints, unless
> > i have an "exit" to stop the processing, the sub jumps back
> > and prints out what i don't want it to. how can i end the
> > cgi at that point without calling exit?
>
> Can you post your code please?
>
> Sounds like:
>
> FILE: while(<FILE>) {
> if($line =~ /somestring/i) {
> # do stuff
> } else {
> error_msg('somestring not found');
> next FILE;
> }
> # do more stuff
> }
>
> HTH,
>
> -dave
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]