in reply to Re: Re: Using CGI params for SQL statement
in thread Using CGI params for SQL statement

Instead of relying on user input for the values of the params 'order_by' and 'order_by_check', you should use a lookup table instead. Consider this: the user enters in their own values instead of using the buttons you supply:
bar.cgi?order_by=foo&order_by_check=bar
Now what? You get a database error. A lookup table is a hash that contains valid keys, the values can be any true value, :
my %lookup = ( FAULT_NO => 'FAULT_NO', ISSUE => 'ISSUE', RESPONSE => 'RESPONSE', ); # task of automating the creation of the hash # is left as an excerise to the reader ;)
Now, instead of just accepting the parameter as is from CGI.pm, you can 'filter' it:
$order_by = $lookup{ param('order_by') }; $order_by_check = $lookup{ param('order_by_check') }; if ($order_by) { ... } ...
When the user enters a value for a field that doesn't exist, the error is treated the same as if the user did not enter any value for a field at all. Works like a charm ... until you want to inform the user of that fact. :(

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)