#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use DBI;
use strict;

print header;
print start_html("Kite Catalog");

my $dbh = DBI->connect( "dbi:mysql:products", "webserver", "", { RaiseError =>
 1, AutoCommit => 1 }) or &dienice("Can't connect to database: $DBI::errstr");

print <<EndHdr;
<h2 align="CENTER">Kite Catalog</h2>
To order, enter the quantity in the input box next to the item.<p>
<form action="order.cgi" method="POST">

my $sth = $dbh->prepare(qq(select stocknum,name,price from items where status != "OUT" order by stocknum)) or &dbdie;

$sth->execute or &dbdie;

while (my($stocknum,$name,$price) = $sth->fetchrow_array) {
   print qq(<input type="text" name="$stocknum" size=5> $name - \$$price<p>\n);

print qq(<input type="submit" value="Order!">\n);

print end_html;

sub dienice {
    my($msg) = @_;
    print "<h2>Error</h2>\n";
    print $msg;

sub dbdie {
    my($package, $filename, $line) = caller;
    my($errmsg) = "Database error: $DBI::errstr<br>
                called from $package $filename line $line";