Php, can't get two variables from url

software development

#1

I’m stuck on this one last detail. In this test php script I’m trying to use _GET to get two variables, site and pcode, from the calling url:

[code]<?php
//test of string manipulation

$site = $_GET[‘site’];
$pcode = $_GET[‘pcode’];
echo $site, ‘
’;
echo $pcode, ‘
’;

//retrieve Prosser flow data from BOR database
$theurl=“http://www.usbr.gov/pn-bin/yak/arc3.pl
."?station=".$site."&year=2000&month=10&day=1&year=2017&month=5&day=20&pcode=$pcode";

echo $theurl, ‘
’;

?>[/code]

When I call the script with a line like lynx -dump http://ykfp.org/php/BOR/teststring.php?site=NACW&pcode=QD

my echo lines show me that I got site set but not pcode. If I change my script call to lynx -dump http://ykfp.org/php/BOR/teststring.php?pcode=QD&site=NACW , I get ‘pcode’ set but not ‘site’. Why can’t I get both set?

If I paste the url string into Firefox, it appears that both site and pcode get set. Is it just lynx that is giving me problems? Do I need to escape the & in the lynx line?


#2

You need to quote the URL; otherwise, the shell ends up trying to run everything up to the & as one command in the background, then the rest as a separate command. Try this on for size:


#3

Jebus! Another four hours of my life wasted while I tried to find the problem in with the php code!