Page 1 of 1
Passing variables in <select>
Posted: Fri Sep 19, 2008 9:59 pm
by 3hhh
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.
Re: Passing variables in <select>
Posted: Fri Sep 19, 2008 10:25 pm
by Christopher
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>
Re: Passing variables in <select>
Posted: Fri Sep 19, 2008 10:37 pm
by 3hhh
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>
Hi,
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>";
}
Re: Passing variables in <select>
Posted: Fri Sep 19, 2008 10:54 pm
by Christopher
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>';
}
Re: Passing variables in <select>
Posted: Fri Sep 19, 2008 11:05 pm
by murp3433
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>
Posted: Sat Sep 20, 2008 12:43 am
by 3hhh
Thanks! It works fine now... Didn't know about the ' and "....
