I'm quit confused with what I have below. I have 2 database tables; Games and groups.
Name Group ############# John , GroupA Miler, GroupA Peter, GroupB Mathew, GroupB Mark, GroupB Luke, GroupA I'm trying to select the members based on their groups and insert them into a different table. I've written my script to receive the names of the group from param() and do the job for me, but something is wrong somewhere that makes the script fail. It inserts members of only one group even if param contains two group. I've modified the script several times, but still not getting the desired result. Assuming the using selected 3 groups and sends them to the script, it should insert members of all the 3 groups into the games table. ################################################ #!/usr/bin/perl -w use CGI; my $obj = new CGI; use vars qw(@groups $group); @groups = $obj->param('groups'); do_db(); ############ Subroutine############## sub do_db { foreach (@groups){ $sth = $dbh->prepare(qq{SELECT Name FROM Groups WHERE Group = "$_"}); $sth->execute(); } while (my @value = $sth->fetchrow_array){ foreach $member (@value){ $dbh->do(qq{INSERT DELAYED INTO Games(Name) VALUES("$member") || print_error("$DBI::err","$DBI::errstr) && die; } } } Your help will be appreciated.