August 27, 2010

PHP Get method not sending full input

Question by Jackass

I have a drop down list that is dynamically generated using a mySQL database using the following code:

$region = mysql_query("select region_name from region", $connection);

echo "<select name=region>Region</option>";

while ($row = $mysql_fetch_array($region))
{
  echo "<option value =$row[region_name]>$row[region_name]</option>";
}

echo "</select>"

This prints out the list perfectly fine however when I submit the form using the GET method any region name that has a space in it will not be passed through properly in the URL. Instead of “South Australia” it will only give me “South”

I know the URL should end up being:
http://foo.com/query.php?region=South+Australia

But instead the +Australia just doesn’t appear.

Anybody know what stupid stuff I’ve done or what I’m missing??

Answer by NAVEED

use single quote for value in option tag:

Try this in while loop:

echo "<option value='$row[region_name]'>$row[region_name]</option>";

Answer by Starx

There is an error in your code………

echo "<select name=region>Region</option>"; should be

echo "<select name='region'><option>Region</option>";

and while giving value do this

echo "<option value='$row[region_name]'>$row[region_name]</option>";

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!