Changeset 237


Ignore:
Timestamp:
Oct 29, 2006, 7:25:53 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Move bad-postcode to using shared error function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/bad-postcode.fcgi

    r222 r237  
    1616use lib "$FindBin::Bin/../perllib";
    1717use NPEMap;
    18 
    19 sub print_err;
    2018
    2119# Set up database handler to try and make sure it's ready for the first
     
    4240    # In case the database went away, make sure we have a connection
    4341    unless ($dbh = setup_dbh()) {
    44         print_err('Error setting up database connection', $returnlink);
     42        print_html_err('Error setting up database connection', $returnlink);
    4543        next REQUEST;
    4644    }
     
    4846    # Input validation
    4947    unless (defined $cgi->param('postcode')) {
    50         print_err ("Postcode identifier not supplied");
     48        print_html_err ("Postcode identifier not supplied", $returnlink);
    5149        next REQUEST;
    5250    }
     
    5553    my $sth = $dbh->prepare('SELECT id FROM postcodes WHERE id = ? AND NOT deleted');
    5654    unless ($sth->execute($cgi->param('postcode'))) {
    57         print_err('Database error when checking for the postcode', $returnlink);
     55        print_html_err('Database error when checking for the postcode', $returnlink);
    5856        next REQUEST;
    5957    }
    6058
    6159    unless ($sth->rows) {
    62         print_err('A postcode with that identifier does not exist, or has already been deleted.', $returnlink);
     60        print_html_err('A postcode with that identifier does not exist, or has already been deleted.', $returnlink);
    6361        next REQUEST;
    6462    }
     
    7472    } else {
    7573        print STDERR "DB error: " . $dbh->errstr . "\n";
    76         print_err("Database error when adding your data :(", $returnlink);
     74        print_html_err("Database error when adding your data :(", $returnlink);
    7775        next REQUEST;
    7876    }
     
    8179# No more requests to serve, so tidy up
    8280$dbh->disconnect;
    83 
    84 # Helper routines
    85 sub print_err($$) {
    86     my $err = shift;
    87     my $returnlink = shift;
    88     print "Content-type: text/html\n\n";
    89     print "<html><head><title>Error submitting</title></head>\n";
    90     print "<body><p>The following error occurred whilst submitting data:\n";
    91     print CGI::escapeHTML($err);
    92     print "<p>$returnlink</p>\n";
    93     print "</body></html>\n";
    94 }
Note: See TracChangeset for help on using the changeset viewer.