#!/usr/bin/perl -wT use strict "vars"; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use DBI; my $query = new CGI; # the four variables from the form: my $email = $query->param('email'); my $CodeIntern = $query->param('CodeIntern'); my $AnzDru = $query->param('AnzDru'); my $Aufla = $query->param('Aufla'); # the global variables are: use vars qw($say $now $data $res); # if NO email-address is given: if (! $email) { $say = "Tja, ohne E-Mail geht's nicht..."; $now = "...probier's nochmal!"; &error_page; } # if a wrong email-address is given: elsif ($email !~ /^[\w-.]+\@[\w-.]+$/) { $say = "Mit der E-Mail ist irgendwas faul..."; $now = "...schau' sie Dir nochmal an!"; &error_page; } # if one of the three choose-points remains empty: elsif (!$CodeIntern or !$AnzDru or !$Aufla) { $say = "Du hast nix angetippt..."; $now = "...probier's nochmal!"; &error_page; } # if everything seems ok: else { &get_price; &show_result; } sub error_page { print $query->header; print <<"EOM" Little error?
;-( $say $now
EOM } sub get_price { print $query->header; my $dbh = DBI->connect("DBI:mysql:soilant_db1:localhost", "user", "pw"); my $sql = "SELECT Preis FROM Preise WHERE CodeIntern = ? AND Aufla LIKE ? AND AnzDru LIKE ? "; my $sth = $dbh->prepare($sql) or die "Sorry, das Präparieren ist grade flöten gegangen: $dbh->errstr"; $sth->execute("$CodeIntern", "$Aufla", "$AnzDru") or die "Sorry, das Execute ist soeben baden gegangen: $dbh->errstr"; $data = $sth->fetchall_arrayref; foreach (@$data){ $res = join (' ', @$_); } } sub show_result { print <<"EOM" The result
;-))) $res $_
EOM $dbh->disconnect; }