----- Original Message -----
From: "Rudolph, Michael" <Michael.Rudolph@telekom.de>
> But my original problem is not really solved
> I read in a date from an input-field of an formular. I now have to
> check, if this input-variable is empty. If it is, I set it to NULL,
> if not, I take it as input.
Unfortunately, there is no way to avoid testing for the empty string and
assigning it to NULL or undef. It would be annoying if the empty string
automatically translated to NULL, because it would be difficult to insert an
empty string into a database.
> My program looks now in parts like this:
> if ($var3 == 0){ $var3 = NULL } # Testing if empty
> else {$var3 = "'$var3'";} # input-field is not empty
> $rc = $dbh->do("INSERT INTO test1 (var1,var2,var3)
> VALUES ('$var1','$var2',$var3)");
You can also do this once for all the form variables instead of doing it
separately for each:
@fields = param();
foreach $current_field (@fields) { if( param($current_field) eq "" ) { param_fetch($current_field)->[0] =
undef; }
}
This assumes you are using CGI.pm, but a similar method should be possible
with the hash returned by ReadParse in cgi-lib or cgi_lite. As always,
there's more than one way to do it. =)
-Mike