Page 1 of 1

$_GET removing text after the space.

Posted: Mon Nov 21, 2011 6:47 am
by dcalladi
Hi, i have some php code in oen file i have some php filling a combo box

Code: Select all

 <select name ="From">
      <?php
            for ($j=0; $j < $rows; $j++)
               {
               $station_name = pg_result($result_set, $j, "station");
               $stations[$j] = $station_name;
			   }
			   for ($i = 0; $i < $results = count($stations); $i++){
				   echo "<option value=".$stations[$i].">".$stations[$i]."</option>";
			   }
?>
This fills up the combo box with info from a database this works fine with the full names. i also tried echo them as well incase that made any difference but it didn't

so when i use the $_GET to move it from one page to another the three stations City Sqaure, Hyde Park and West Park turn to Cit, Hyde, West when i try to echo them or use thme with anything.
so my conclusion was that the $_GET was messing with them.

Code: Select all

 To : <?php echo urldecode($_GET["From"]);?>
is what i am using to echo them. iv'e had a look for answers around but there isn't much on the top and wehat there is doesn't help just wondering if anyone could help.

Re: $_GET removing text after the space.

Posted: Mon Nov 21, 2011 7:05 am
by Celauran

Code: Select all

echo "<option value=".$stations[$i].">".$stations[$i]."</option>";
Looks to me like this line is going to cause you problems. You don't have quotes around your value, so you'll end up with things like

Code: Select all

<option value=Hyde Park>Hyde Park</option>
The space will cause value to be read simply as Hyde. What you want is

Code: Select all

<option value="Hyde Park">Hyde Park</option>
So you just need to add in some quotes:

Code: Select all

echo "<option value=\"{$stations[$i]}\">{$stations[$i]}</option>";