$_GET removing text after the space.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dcalladi
Forum Newbie
Posts: 2
Joined: Sat Nov 19, 2011 4:56 pm

$_GET removing text after the space.

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: $_GET removing text after the space.

Post 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>";
Post Reply