After many hours of frequent frustration and alliteration I decided to ask for your collective advice. Here is the skinny.
I have a form with about 30 form elements including 2 multiple selects (location and domain). This form uses the method get. My script is to use CGI.pm to parse the data from CGI. I test each param from my form to create a single where statement, $where. This is use to create an SQL select statment. An example of the select statement could be, "SELECT * from mytable where server LIKE %someserv% AND (location = 'San Antonio' OR location = 'Austin')"
Now on to the question. I had implemeted a routine in several scripts to handle SQL insertions and updates automatically by parsing out the keys and values from CGI. Becasue of this I began toying with the object oriented functionality of CGI.pm. This would allow me to assign the CGI params and values to a hash(%IN) and A)do a 'delete $IN{submit};' or $IN{myparam} = $someval and B)not have to assign my 30 or so params using my $param = param("someparam") either with global scope or passing many of them to several subroutines.
I am able to get the Object Orinted functionality working using the following code:
use strict;
use CGI;
my ($cgi, $key, %IN);
$cgi = new CGI;
%IN = $cgi->Vars; #%IN = (param1 => value1, param2 => value2 , etc..);
Though I am having issues attempting to handle multiple selects. See the code below for a failed example.
if (defined $IN{location}) {
$where .= "AND (location = '$IN{location}[0]'";
for my $i (@{$IN{location}}) { $where .= "$i" };
$where = "$where)";
}
Below is an example of one of my insert routines from my other scripts.
delete $IN{somekey};
delete $IN{somekey1};
delete $IN{somekey2};
delete $IN{somekey3};
$IN{somekey4} = "someval";
foreach $key (keys %IN) {
$keys[$i] = $key;
$value = $IN{$key};
$value = $dbh->quote($value); #removes quotes from the values
$values[$i] = $value;
$i++;
}
my $key_string = join(',',@keys); #joins array elements, and status a
+nd adds a comma
my $value_string = join(',',@values"); #joins array values, and stat
+us, and adds a comma
$sql = "$function $tablename ($key_string) values ($value_string)";
$sth = $dbh->prepare($sql);
$sth->execute();
What is the best way to handle the CGI from a form with a large amount of elements and with multiple selects? Should I use the object oriented functionality? If so how do I handle multiple selects?