I have a Perl CGI script that runs a query against a MySQL table. I have about 20 boolean values that I want shown as checkboxes in the produced HTML, but I don't want to have to do something like the below for every value.

[code]
if($ref->{somevalue}) {
  print "<input type=checkbox name=somevalue value=1 checked>";
} else {
  print "<input type=checkbox name=somevalue value=1>";
}
[/code]

Converting back is easy enough:

[code]
use CGI;
my $cgi = new CGI;
my $p = $cgi->Params;

$somevalue = $p->{somevalue} or $somevalue = 0;
[/code]

If it was checked, it will be passed along with a value of 1. If it's not checked, it won't be passed along and will return undef if I try to grab it from the $p hash. Although, how could I quickly convert all the values back for something like:

[code]
$dbh->do("UPDATE table SET somevalue1='$p->{somevalue1}', somevalue2='$p->{somevalue2}', somevalue3='$p->{somevalue3}', somevalue4='$p->{somevalue4}', somevalue5='$p->{somevalue5}', somevalue6='$p->{somevalue6}'");
[/code]


Would MySQL choke if it was expecting a non-null integer value for all of those? If so, how can I handle that without a lot of code? I currently handle the data both ways by having a textfield with a '1' or '0' in the generated HTML, but it looks ugly.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to