Hi,
I have the following code:
<select name=test>
<option value=first result>first result</option>
<option value=second result>second result</option>
</select>
When I do a $_POST['test'], it returns "first" instead of "first result" and "second" instead of "second result". Why is that so? Kindly advise. Thanks.
Passing variables in <select>
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Passing variables in <select>
You should quote all property values:
Code: Select all
<select name="test">
<option value="first result">first result</option>
<option value="second result">second result</option>
</select>(#10850)
Re: Passing variables in <select>
Hi,arborint wrote:You should quote all property values:Code: Select all
<select name="test"> <option value="first result">first result</option> <option value="second result">second result</option> </select>
Yes I did that. This is my actual code:
echo "<select name=\"venue\" class=\"normal\">";
if ($result=mysql_query($sql)) {
while ($row=mysql_fetch_row($result)) {
echo "<option value=".$row[0].">".$row[0]."</option>";
}
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Passing variables in <select>
No, you did not have quotes around the values:
Code: Select all
echo '<select name="venue" class="normal">';
if ($result=mysql_query($sql)) {
while ($row=mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[0].'</option>';
}(#10850)
Re: Passing variables in <select>
arborint wrote:No, you did not have quotes around the values:Code: Select all
echo '<select name="venue" class="normal">'; if ($result=mysql_query($sql)) { while ($row=mysql_fetch_row($result)) { echo '<option value="'.$row[0].'">'.$row[0].'</option>'; }
Also if you alternate between single and double quotes you wont have to use escapes. Not a big deal just good practice as it makes your code more readable.
echo '<select name="venue" class="normal">';
Re: Passing variables in <select>
Thanks! It works fine now... Didn't know about the ' and ".... 