in reply to Re: Re: Re: Re: Multiple Check boxes and Handling
in thread Multiple Check boxes and Handling
Move your &Create_DB_Connection outside the loop (you only need to do it once. It looks as though you are fairly unfamiliar with DBI so here is a start. I just typed this out so there are probably typos/syntax errors.
#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp('fatalsToBrowser'); use DBI; my $home = $ENV{HOME}; my $q = new CGI; # get rows to delete my @deletes = $q->param('delete_this_row'); # print a header using CGI.pm print $q->header(); # connect to database, only need to do once (fill in values) my $dbh = DBI->connect($data_source, $username, $auth, \%attr) or erro +r("Can't connect to database!"); # prepare and cache SQL - we use a placeholder ? ALWAYS USE ? placehol +ders! my $SQL="DELETE FROM timeclock WHERE oid = ?"; my $sth = $dbh->prepare_cached($SQL) or error("Could not prepare $SQL" +); # do the deletions my $results; foreach my $delete(@deletes) { $sth->execute($delete) or error("Could not execute $detete"); $results .= "<LI>Deleted $delete</LI>\n"; } # commit the changes $dbh->commit or do {$dbh->rollback; error("Could not commit changes")} +; $dbh->disconnect or error("Disconnect error"); sub error { my $error = shift; print "<h2>Database error!</h2>\n" print "<p>$error " . $DBI::errstr; exit; } ################ BEGIN PRINT RESULTS SUBROUTINE sub print_results{ print <<HTML; <HTML><HEAD><TITLE>Delete Entry</TITLE></HEAD> <BODY BGCOLOR="#FFFFFF"> <CENTER><FONT SIZE=6 FACE=ARIAL>Delete Results</FONT></CENTER> <HR WIDTH=80%> <P> <CENTER> <UL> $results </UL> </CENTER> <P> <HR WIDTH=80%> <P> <CENTER> <FONT SIZE=4 FACE=ARIAL> <a href="$home">Home</A> |<a href="in_form.cgi">Clock In</A> | <a + href="search_form.cgi">Search</A> </FONT> </CENTER> </BODY> </HTML> HTML } # End of print_results subroutine
Totally untested. See btrott for a basic guide to DBI and the DBI pod.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|