Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Value not being interpreted

by Milti (Beadle)
on Dec 30, 2021 at 17:12 UTC ( [id://11140037]=perlquestion: print w/replies, xml ) Need Help??

Milti has asked for the wisdom of the Perl Monks concerning the following question:

I am using the GET command to retrieve customer info. When the customer name includes the ampersand, example Joe & Jane, the printout returned is only "Joe". Here is the GET call being used:

www.mysite.com/cgi-bin/customer_info_get.pl?f5=CID&f6=Joe & Jane

The cgi definitions are: $EID="$FORM{'f6'}"; and $customer ="$FORM{'f5'}"; The print command is: print "<font size=\"3\"><b>Customer Info For -- <font><font size=\"5\"><u>$EID</u></b></font>";

This print command does not return Joe & Jane, only Joe. However, if I change the code to print CINFO "<font size=\"3\"><b>Customer Info For -- <font><font size=\"5\"><u>Joe & Jane</u></b></font>" then Joe & Jane are printed out. It seems the command is correct. The question is why is the ampersand not being interpreted as part of the variable $EID.

<Any and all assistance will be appeciated.

Thanks for all the suggestions. The problem has been solved. Rather than asking the cgi program to "escape" the ampersand, it was removed from the GET query by changing f6=Joe & Jane to f6=Joe %26 Jane. That change results in Joe & Jane being printed.><Thanks again!>

Replies are listed 'Best First'.
Re: Value not being interpreted
by tangent (Parson) on Dec 30, 2021 at 22:00 UTC
    As pointed out you need to escape the ampersand in 'Joe & Jane' but you do not want to escape the other ampersand in 'CID&f6'. Other characters may also need escaping so best to use a module:
    use URI; my $uri = URI->new('www.mysite.com/cgi-bin/customer_info_get.pl'); $uri->query_form( f5 => 'CID', f6 => 'Joe & Jane', ); print "$uri";
    Output:
    www.mysite.com/cgi-bin/customer_info_get.pl?f5=CID&f6=Joe+%26+Jane
Re: Value not being interpreted
by LanX (Saint) on Dec 30, 2021 at 18:11 UTC
    >  ?f5=CID&f6=Joe & Jane

    & is a query delimiter, you are even explicitly using it as such. Consider URL-encoding it in the value for f6

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re: Value not being interpreted
by Anonymous Monk on Dec 30, 2021 at 21:27 UTC
    %FORM is a red flag, make sure youre using CGI param

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11140037]
Approved by LanX
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-09-08 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.