#!/usr/bin/perl -w use strict; use warnings; # snip... # connect to DB $dbh = DBI->connect( q[DBI:mysql:] . qq[database=$DATABASE;] . qq[host=$DBHOST;] . qq[port=$DBPORT], $DBUSER, $DBPASS, { 'RaiseError' => 0, 'AutoCommit' => 1 } ) or do { # gently tell visitor we had an embarrassing uh-oh occur. cgi_error(<<__ERR__);
An internal error has occurred on the webserver. The server administrator has been notified of the error. It will be fixed as soon as possible.
We appologize for the inconvenience.
__ERR__ # try to let administrator know there was a big problem ¬ify_admin('failed to connect to database! ' . $DBI::errstr); }; my($photolog) = $dbh->selectrow_hashref(<<'__SQL__', undef, $plogid) SELECT *,DATE_FORMAT(created,'%m/%d/%Y') AS fcreated FROM photologs WHERE id = ? __SQL__ or do { cgi_error(qq{Couldn't get photolog info for the requested photolog ID.}); notify_admin(<<__ERR__) Problem getting photolog record id "$plogid"! $DBI::errstr __ERR__ }; my($name) = $cgi->param('name'); my($email) = $cgi->param('email') || '[not specified]'; my($comments) = $cgi->param('comments'); cgi_error(q{Please go back and provide your comments. (Duh)}) unless defined $comments and length $comments; cgi_error(q{Anonymous comments aren't accepted. Please go back provide your name this time (or make up a good fake one.)}) unless defined $name and length $name; $dbh->do( <<'__SQL__', INSERT INTO comments ( photologid, name, email, comments, ipaddr, comment_date ) VALUES (?,?,?,?,?,NOW()) __SQL__ undef, $plogid, $name, $email, $comments, ( $ENV{'REMOTE_ADDR'} || '000.000.000.000' ) ) or do { cgi_error(qq{Couldn't add visitor comments. We're sorry!}); notify_admin(<<__ERR__) Problem adding visitor comments to photolog id "$plogid"! $DBI::errstr __ERR__ }; my($msgid) = $dbh->{'mysql_insertid'};