Dear monks,

Try as I might, I have searched through the archives and even looked at CGI.pm but have not been able to work out what I am doing wrong.

I have an HTML form with six checkboxes all formatted as such:

<input type="checkbox" name="chk1" value="Listname" onclick="sql()" />

The JavaScript just links to a text box and shows the query being created so the user can check it before sending it to the db.

The name goes from chk1 to chk6 and the value names correspond to column names in a MySQL db. What I need to do is to pass the checked values to a Perl script which is combining all of the values and creating the SQL query. Whilst I can get the rest of the SELECT script to build correctly, I have been unable to get this first section which defines the relevant columns to search to work.

If have tried using:

if (exists $fd{chk1} ) { push @columns }
and
if ($fd{chk1} eq "Listname") { $columns = $db->quote($fd{$_}) .","; }

What I was trying to do was to pop the column names into an array, @columns, and then assign the array to $columns which the SELECT command calls but I have managed to lose my way somewhat.

I would be very grateful for any help so I can learn what I have done incorrectly.

Many thanks in advance.


In reply to Checkboxes into an SQL Select query by Quicksilver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.