Gossamer Forum
Home : General : Perl Programming :

Please help with checkboxes

Quote Reply
Please help with checkboxes

Here is my problem, (I'm starting to pull out my hair). I have a script that adds to a database. Some of my fields have multiple values that I add through checkboxes. When I add a record and have multiple values for one of the fields, they all appear as though it's one word. How can I split the values of the checkbox so that I can read them later on as seperate values. Here is the way the script processes the fields to the database. I am not using cgi.pm

foreach $field (@db_fields)
$new_row .= "$form_data{$field}|";

chop $new_row;

$new_row .= "\n";

if (!$flock) { &get_file_lock("$location_of_lock_file"); }
open (DATABASE, ">>$data_file_path") ||
&file_open_error ("$data_file_path", "Submit Addition",
__FILE__, __LINE__);
if ($flock) { flock DATABASE, 2; }
print DATABASE $new_row;
close (DATABASE);

Thank a lot for your help

Quote Reply
Re: Please help with checkboxes In reply to

$new_row .= "$form_data{$field}|";

If you want a space inbetween each entry, try adjusting the above line to:

$new_row .= "$form_data{$field} | ";

By simply adding spaces it should write the spaces into your file.

Of course, you can also use other control characters like:

/t tab
/n new line

So you could have:

$new_row .= "$form_data{$field} \t|\t";

To put a tab inbetween each field.

Anyway, I'm not sure exactly how you want to lay out the data, but hope this helps to get you started.

Wil Stephens