Hi Monk

I have a webpage from which I am selecting some values to construct my sql query in my cgi script. For exanple, the webpage has the following content as its page source ,

<html> <table> <tr> <td><select name='OPENBRACK1'> <option value=''></option> <option value='('>(</option> </td> <td> <select name='FIELD1'> <option value='CITY'>CITY</option> <option value='NAME'>NAME</option> </select> </td> <td > <select name='COMP1'> <option value='like'>like</option> <option value='notlike'>not like </option <td> <input type=text name='VALUE1' maxlength=40 size=30 value=''></td> <td ><select name='CLOSEBRACK1'> <option value=''></option> <option value=')'>)</option> </td> <tr> <td colspan=7 align=center> <input type='hidden' name='NoOfRows' value="1" /> <input type="button" value="Add Condition" onclick="addRowToTable();" +name="AddCondition" /> </td> </tr> </table> </html>

By the "Add condition" button , I add a similar line of table data in the webpage. And assume that, I collect all these param infos in my cgi script as,

$br1 = $cgi->param('OPENBRACK1'); $field1 = $cgi->param('FIELD1'); $value1 = $cgi->param('VALUE1'); $comp1 = $cgi->param('COMP1'); $br2 = $cgi->param('OPENBRACK2'); $field2 = $cgi->param('FIELD2'); $value2 = $cgi->param('VALUE2'); $comp2 = $cgi->param('COMP2');

So, upon submitting all these in a form, assume that I have all these infos in my cgi script. Now from these param infos how can I contruct a query like this :

select NAME,CITY from MyTable where NAME like %xyz% and CITY not like %abc%;

Please help me with the logic or if there is any other built-in mechanism in cgi perl (some function or ENV variables) which will help me construct such a query.
The diffculty I am facing is how many 'AND' or 'OR' conditions have been used by 'Add condition' button or so.Hope I could explain my problem clearly.

Thanks.


In reply to query construction from cgi perl params by ghosh123

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.