Parsing query string from cgi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Parsing query string from cgi
# 1  
Old 05-02-2005
Parsing query string from cgi

Im having trouble getting the string I get from a cgi form to only be the value entered. I need to use that value as an argument but cant use it in the way it is returned. I get "bustype = restaurant" but I want just "restaurant" because i am going to be using that value as an argument in a csh file to display a table from mysql. I know it should be simple but I cant get it to work. Thanks.
# 2  
Old 05-02-2005
how do you get the string to come up? is it like "grep bustype somefile" or something like that?
# 3  
Old 05-02-2005
Do something like this if using POST
Code:
# process POST key / value pairs
read( STDIN, $query_string, $ENV{ 'CONTENT_LENGTH' });

@key_value_pairs = split ( /&/, $query_string );
  foreach $key_value ( @key_value_pairs ) {
    ( $key, $value ) = split ( /=/, $key_value );
    $value =~ tr/+/ /;
    $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ( $1 ) )/eg;
    $FORM{ $key } = $value;
}

Then you can access the elements, e.g.
$FORM{ 'foo' }
would correspond to the form control with name="foo" in it's tag in your html page.

Cheers
ZB
# 4  
Old 05-03-2005
For Perl, extracting a query parameter does not need to be verbose as that.

Code:
use CGI;
$cgi = new CGI();
$bustype = $cgi->param('bustype');

For csh CGI script, I can't help as I don't use it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

3. Shell Programming and Scripting

String parsing

Hi, name=VDSL_TTV_ HN_SUB create coid=MA5603U phone=5678 portpolicy=APortSelectionPolicy rfu10=TTV rfu3=Dot1q sz7_portmode=VDSL2 rfu5=1234 srprofile.sy_profname=$ADSL_TTV_SubProfile1 I have a line like this. Its a single line.I need the output as name=VDSL_TTV_ HN_SUB create... (1 Reply)
Discussion started by: giri_luck
1 Replies

4. Shell Programming and Scripting

String-parsing!

I need the perl solution for the following : $string="I LOVE INDIA" now, in a new string i need the first character of each word... that is string2 should be "ILN". (10 Replies)
Discussion started by: vijay_0209
10 Replies

5. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

6. Programming

parsing string in c

how can i remove the special characters hi iam print the string variable . suppse: while(str!=NULL) printf("******* %s ********** %d ",str,strlen(str)); output as: ****srinu ******** 5 **** phani******** 63 ****srinu ******** 5 **** phani******** 63 so my problem is how can i... (3 Replies)
Discussion started by: phani_sree
3 Replies

7. Shell Programming and Scripting

Need help on parsing string

String example: /vmfs/volumes/46000471-71d7c414-8f74-0013210cddc3/gistst/gistst.vmx What I would like to do is create a variable and save gistst in it. I thought if I could create an array and split it by '/' then I could use the 4th array element or if they was a way to do a... (13 Replies)
Discussion started by: magnacrazy
13 Replies

8. Shell Programming and Scripting

Perl CGI Query

Hi All, This is quite a high level question so I appologise as if it sounds a bit woolly! I'm running a script via apache's cgi-bin that calls another Perl script (from a browser): http://192.168.000.000/cgi-bin/run_script.pl?SCRIPT=test.pl&text=RANDOM+TEXT&INPUT1=444444444444 This... (4 Replies)
Discussion started by: pondlife
4 Replies

9. Shell Programming and Scripting

HTTP Query Request & Parsing returned XML output

I have a PERL script from which I need to make a HTTP request to Web Servlet (Essentially a URL with variables and values like &Variable1=AAAAAA&Variable2=BBBBBBBBB&Variable3=CCCCCCC). The Web servlet returns an XML result which needs to be parsed for the contents of the result within the program.... (15 Replies)
Discussion started by: jerardfjay
15 Replies

10. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies
Login or Register to Ask a Question