Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

query construction from cgi perl params

by ghosh123 (Monk)
on Jul 25, 2012 at 18:27 UTC ( #983712=perlquestion: print w/replies, xml ) Need Help??
ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://983712]
Approved by herveus
help
Chatterbox?
Discipulus second time; no questions.. o tempora o mores..
[1nickt]: I understood the first version ;-)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-11-24 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (354 votes). Check out past polls.

    Notices?