|< 1 2 3 4 ... 9 >| | 85 Einträge, 9 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!f:/Perl/bin/perl -w
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $DBH;
my $STH;
my $CGI;
my $antwort;
$CGI = new CGI();
### Suche oder Eintrag ###
if ($CGI->param("suchanfrage")){
suche($CGI, $DBH, $STH);
}
elsif($CGI->param("eintrag")){
eintragen($CGI, $DBH, $STH);
}
### Start Subroutine Suche ###
sub suche{
my $name = param("name");
my $kundennummer = param("kundennummer");
$DBH = DBI->connect("DBI:CSV:Kunden=f:/Apache2/cgi-bin")
or die "Konnte keine Verbindung zur Datenbank herstellen:$!";
$STH = $DBH->prepare("SELECT * FROM Kunden WHERE Name = '$name' AND Kundennummer = '$kundennummer' ")
or die "Konnte SQL-Statement nicht bereitstellen:$!";
$STH->execute()
or die "Ausfuehren nicht moeglich:$!";
### Treffer ###
if ($STH->rows != 0){
print <<HERE_TEXT1;
Content-type:text/html
<HTML>
<HEAD>
<TITLE> Antwort </TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>Suchergebnis:</H1>
<HR>
<TABLE BORDER>
<TR>
<TD WIDTH="200"><B>Name:</B></TD>
<TD WIDTH="100"><B>Kundennummer:</B></TD>
<TD WIDTH="200"><B>Adresse:</B></TD>
<TD WIDTH="100"><B>Telefonnummer:</B></TD>
</TR>
HERE_TEXT1
my @data;
while (@data = $STH->fetchrow_array()) {
my $name = $data[0];
my $kundennummer = $data[1];
my $adresse = $data[2];
my $telefonnummer = $data[3];
print qq§<TR>\n<TD><B>$name</B></TD>\n<TD>$kundennummer</TD>\n<TD>$adresse</TD>\n<TD>$telefonnummer</TD>\n</TR>\n§;
}
### Keine Treffer ###
else {
print <<HERE_TEXT2;
Content-type:text/html
<HTML>
<HEAD>
<TITLE>Antwort</TITLE>
</HEAD>
<BODY>
<P>Leider brachte die Suche nach '$name' keine Ergebnisse!</P>
<HR>
<P><A HREF =\"../formular1.html\">Neue Suche!</A></P>
</BODY>
</HTML>
HERE_TEXT2
}
$STH->finish();
$DBH->disconnect;
}
### Ende Subroutine Suche ###
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! f:/Perl/bin/perl -w
use strict;
use warnings;
use CGI ();
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use DBI;
use vars qw($CsvPath);
$CsvPath = 'f:/Apache2/cgi-bin';
# oder besser, wenn Readonly vorhanden ist:
# use Readonly $CsvPath => 'c:/Programme/ApacheGroup/Apache/cgi-bin';
my $cgi = CGI->new();
my %params = $cgi->Vars();
print $cgi->header();
if ( exists $params{suchanfrage} ) { &Suche ($cgi, \%params) }
elsif( exists $params{eintrag} ) { &Eintragen($cgi, \%params) }
else { &Startseite($cgi, '...') }
print $cgi->end_html();
# ------------------------------------------------------------
sub Suche {
my ($cgi, $params) = @_;
my $dbh = &ConnectToDB();
$cgi->start_html('Antwort');
my $sqlStatement = qq~SELECT Tabelle1.Kundennummer, Tabelle1.Name,
Tabelle1.Telefon, Tabelle2.Rechnungsbetrag
FROM Tabelle2 JOIN Tabelle1
WHERE Tabelle2.Kundennummer = Tabelle1.Kundennummer~;
my $sth = &FireSql($dbh, $sqlStatement);
if ($sth->rows < 1) {
print $cgi->p("Keine Daten gefunden");
return;
} # if
print qq~
<center>
<h1>Suchergebnis:</h1>
<hr />
<table border="2">
<tr>
<td width="200"><b>Kundennummer:</b></td>
<td width="200"><b>Adresse:</b></td>
<td width="200"><b>Name:</b></td>
<td width="200"><b>Telefonnummer:</b></td>
<td width="200"><b>Rechnungsbetrag:</b></td>
</tr>\n~;
while( my @data = $sth->fetchrow() ) {
printf qq~
<tr>
<td><b>%s</b></td>
<td><b>%s</b></td>
<td><b>%s</b></td>
<td><b>%s</b></td>
</tr>\n~,
@data[0, 1, 2, 3];
} # while
$sth->finish();
$dbh->disconnect();
} # Suche
# ------------------------------------------------------------
sub Eintragen {
} # Eintragen
# ------------------------------------------------------------
sub ConnectToDB {
my $dsn = "DBI:CSV:Kunden.mdb=$CsvPath";
my $dbh = DBI->connect($dsn)
or die "Error: couldn't connect to '$dsn': $DBI::errstr\n";
return $dbh;
} # ConnectToDb
# ------------------------------------------------------------
sub FireSql {
my ($dbh, $sqlStatement, @values) = @_;
my $sth = $dbh->prepare($sqlStatement)
or die "Error: couldn't prepare sql: $DBI::errstr\n$sqlStatement\n";
$sth->execute(@values)
or die "Error: couldn't execute sql: $DBI::errstr\n$sqlStatement\n";
return ($sth);
} # FireSql
# ------------------------------------------------------------
else { &Startseite($cgi, '...') }
my $dsn = "DBI:CSV:Kunden.mdb=$CsvPath";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! f:/Perl/bin/perl -w
use strict;
use CGI qw(:standard);
use DBI;
my $dbh = DBI->connect('DBI:ODBC:Kunden');
my $cgi = CGI->new();
my %params = $cgi->Vars();
print $cgi->header();
if ( exists $params{suchanfrage} ) { &Suche ($cgi, \%params) }
elsif( exists $params{eintrag} ) { &Eintragen($cgi, \%params) }
else { &Startseite($cgi, '...') }
print $cgi->end_html();
# ------------------------------------------------------------
sub Suche {
my ($cgi, $params) = @_;
my $dbh = &ConnectToDB();
$cgi->start_html('Antwort');
my $sqlStatement = qq§SELECT Tabelle1.Kundennummer, Tabelle1.Name,
Tabelle1.Telefon, Tabelle2.Rechnungsbetrag
FROM Tabelle2 JOIN Tabelle1
WHERE Tabelle2.Kundennummer = Tabelle1.Kundennummer~;
my $sth = $dbh->prepare($sqlstatement);
$sth->execute ||
die "Could not execute SQL statement ... maybe invalid?";
my $sth = &FireSql($dbh, $sqlStatement);
if ($sth->rows < 1) {
print $cgi->p("Keine Daten gefunden");
return;
} # if
print qq~
<center>
<h1>Suchergebnis:</h1>
<hr />
<table border="2">
<tr>
<td width="200"><b>Kundennummer:</b></td>
<td width="200"><b>Adresse:</b></td>
<td width="200"><b>Name:</b></td>
<td width="200"><b>Telefonnummer:</b></td>
<td width="200"><b>Rechnungsbetrag:</b></td>
</tr>\n~;
while( my @data = $sth->fetchrow() ) {
printf qq~
<tr>
<td><b>%s</b></td>
<td><b>%s</b></td>
<td><b>%s</b></td>
<td><b>%s</b></td>
</tr>\n~,
@data[0, 1, 2, 3];
} # while
$sth->finish();
$dbh->disconnect();
} # Suche
# ------------------------------------------------------------
sub FireSql {
my ($dbh, $sqlStatement, @values) = @_;
my $sth = $dbh->prepare($sqlStatement)
or die "Error: couldn't prepare sql: $DBI::errstr\n$sqlStatement\n";
$sth->execute(@values)
or die "Error: couldn't execute sql: $DBI::errstr\n$sqlStatement\n";
return ($sth);
} # FireSql
# ------------------------------------------------------------
|< 1 2 3 4 ... 9 >| | 85 Einträge, 9 Seiten |