#!/usr/bin/perl -Tw
use strict;
#use lib qw\/usr/dom/xbrie/brian/Hughes/perl\;
## set the path
#$ENV{"PATH"} = "/usr/local/bin:/usr/ucb:/bin:/usr/bin";
use CGI qw(:standard);
#use CGI::Carp;
use DBI;
my $dbh = DBI->connect("DBI:mysql:book","user", "password");
$|++; # Make the pipes piping hot!
my $cgiquery = new CGI;
my $myself = $cgiquery->self_url;
print $cgiquery->header(-expires=>'now');
print $cgiquery->start_html(-"title"=>'Database funtionality',
-"author"=>'brian@brie.com',
-"meta"=>{'keywords'=>'brians database',
'copyright'=>'Copyright 1997 Big Brie'},
-"BGCOLOR"=>'white');
print qq{\n};
print " Developed by the man himself ";
# I moved search results up so I took out this link to it.
#if ($keyword) { #Make a quick link to the results
# print qq{See Results by scrolling down};
#}
# Start the Form part of html for any and all forms on page. This must go before any form elements
print $cgiquery->startform (-method=>'get');
# Search form of page
print "Database Interface
\n";
print '
Mr. Brian Lavender' , "\n";
#
# Do we have a search submitted
#
my $keyword;
if ($cgiquery->param('keyword')){ #assigns keyword to scalar
$keyword = $cgiquery->param('keyword');
}
$keyword =~ s/(.*)/\U$1/g;
print "Search the Database
\n";
print qq{Will search the "approved data" table below
\n};
print "in name and city columns only\n";
print "
\n"; print "Search Keyword (10 characters max): ", $cgiquery->textfield(-name=>'keyword', -size=>10, -maxlength=>10); print " ",$cgiquery->submit(-name=>'add', -value=>'search'); print "\n"; print "
", $_ , " | \n"; } print "
---|
", $_ , " | \n"; } print "
\n";
# Get data for new insert
print "Customer Number (xxxx): ", $cgiquery->textfield(-name=>'cnum',
-size=>4,
-maxlength=>4,
-override=>1);
print "
\n";
print "Customer Name (10 Char max): ", $cgiquery->textfield(-name=>'cname',
-size=>12,
-maxlength=>10,
-override=>1);
print "
\n";
print "City (10 Char max): ", $cgiquery->textfield(-name=>'city',
-size=>12,
-maxlength=>10,
-override=>1);
print "
\n";
print "Rating (xxx): ", $cgiquery->textfield(-name=>'rating',
-size=>3,
-maxlength=>3,
-override=>1);
print "
\n";
print "Salesman No (xxxx): ", $cgiquery->textfield(-name=>'snum',
-size=>4,
-maxlength=>4,
-override=>1);
print "
\n"; print $cgiquery->submit(-name=>'add', -value=>'Data Insert'); print $cgiquery->endform , "\n"; print "
\n";
#place all the values from the form into a scalar
my $cnum= $cgiquery->param('cnum');
my $cname= $cgiquery->param('cname');
$cname =~ s/(.*)/\U$1/g; # Uppercase this thing
my $city= $cgiquery->param('city');
$city =~ s/(.*)/\U$1/g; # I know I should use a subroutine
my $rating= $cgiquery->param('rating');
my $snum= $cgiquery->param('snum');
if ( $cgiquery->param('cnum') && ($cgiquery->param('add') eq 'Data Insert') ){
# local ($Msql::QUIET) = 1;
print "$cnum $cname $city $rating $snum
\n";
my $query = "insert into entries values ($cnum, '$cname','$city', $rating , $snum)";
my $sth = $dbh->prepare($query);
if ($sth -> execute){
print "
It made it here
\n";
}else{
print "The insert failed
\n";
}
}
# This is the stuff in storage
print qq{\n};
print "This is all the "approved data" in Storage
\n";
print qq{TOP \n
\n}; my $query = "select * from customers"; my $sth = $dbh->prepare($query); $sth->execute; print "
", $_ , " | \n"; } print "
---|
", $_ , " | \n"; } print "
Brie Web Publishing
PO Box 19184
Sacramento, CA 95819
(916) 443-6195