Helllo,

Here is part two:
  
Goal: delete selected records and refresh display_guestbook.cgi page.
So the users sees the changes made.

Please let me know how I can Improve my script and if you see anything that is
bad style/practice.
Thanks in advance for the lists help this code,  

Regards from Ft. Worth,

Dave 

-----script to delete records from mySQL database----  

#!/usr/bin/perl -w

# update_guestbook.cgi

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use strict;

my $user_name = "###";
my $user_password = "###";
my $sql_server = "####";
my $table_name = "guestbook";

my @guests_to_delete;
my $path_to_cgi = ######";
my ($sql,$dbh,$sth);
my $secret_word  = '###';


@guests_to_delete = param('id');


&initialize_dbi;

#######################

foreach (@guests_to_delete){
    $sql = "delete from $table_name where id =?";
    $sth = $dbh->prepare($sql);
    $sth->execute($_);
}


$dbh->disconnect; # close date base connection 

# cause guestbook page to be refreshed  
print redirect("./display_guestbook.cgi?$secret_word");


exit;

sub initialize_dbi{
   my $drh = DBI->install_driver( 'mysql' );
   $dbh = DBI->connect("DBI:mysql:$user_name:$sql_server", $user_name, $user_password);
   die "Cannot connect: $DBI::errstr\n" unless $ ;
}


__END__
==============================================
         Cora Connection: Your West African Music Source
              Resources, Recordings, Instruments & More!
                   <http://www.coraconnection.com/> 
==============================================

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to