tags:

views:

19

answers:

3

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??

+1  A: 

use single quote for value in option tag:

Try this in while loop:

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

That would be because you're required to quote HTML attributes:

<option value="South Australia">...</option>

Otherwise, how is the browser supposed to distinguish between one attribute and the next?

<option value=South Australia>...</option>

The browser reads that as one attribute called 'value' with the value 'South' and another attribute called 'Australia'.

Try validating your HTML, it'll find other errors as well, as Starx points out..

deceze
+1  A: 

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>";
Starx