By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

HTML and PHP question (not assinging any value)

P: n/a

Hello group,

I have switched to linux and PHP so totally new to this field. Please
help me with my question. I have an HTML code which contains a
drop-down control on it using
<select name=selected_group>
<option> Gropu 1</option>
<option> Group 2</option>
and ...
</select>
<?php
$group = $_POST['selected_group'];
?>

meantime, I'm my php code using $group = $_POST['selected_group'] but
nothing will assinged to the $group variable. I tried different html
codes which were on web for learning purpose but didn't work out!
please let me know if you have any suggestions.

Thanks,
Amit

Jun 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
amit wrote:
<select name=selected_group>
<option> Gropu 1</option>
<option> Group 2</option>
and ...
</select>


Each option needs to have a value assigned. The text between <option>
and </option> is only visual and is not used for the actual form-data
when submitting it to the server. Hence, the code quoted above will
submit an empty value for "selected_group" regardless of what's actually
selected.

This is how you should do it:

<select name="selected_group">
<option value="Group 1">Group 1</option>
<option value="Group 2">Group 2</option>
</select>

This way, when the form is submitted, what you've defined in the
value-parameter is what is actually sent to the server.
Roy W. Andersen
--
ra at broadpark dot no / http://roy.skyggenesdal.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Jun 18 '06 #2

P: n/a
amit wrote:
Hello group,

I have switched to linux and PHP so totally new to this field. Please
help me with my question. I have an HTML code which contains a
drop-down control on it using
<select name=selected_group>
<option> Gropu 1</option>
<option> Group 2</option>
and ...
</select>
<?php
$group = $_POST['selected_group'];
?>

meantime, I'm my php code using $group = $_POST['selected_group'] but
nothing will assinged to the $group variable. I tried different html
codes which were on web for learning purpose but didn't work out!
please let me know if you have any suggestions.

Thanks,
Amit


The value of 'selected_group' is only assigned to the $_POST value when
the form submit action is invoked and the form is using a POST method.

So:
1. is your <select> within a <form>?
2. does the <form> have method="POST"?
3. does the <form> also contain an <input type="submit"> or onchange= to
the select?

If not, $_POST['selected_group'] will not be set and $group will be empty.

-david-

Jun 18 '06 #3

P: n/a
"Roy W. Andersen" <ro******@netgoth.org> wrote:
amit wrote:
<select name=selected_group>
<option> Gropu 1</option>
<option> Group 2</option>
and ...
</select>
Each option needs to have a value assigned. The text between <option>
and </option> is only visual and is not used for the actual form-data
when submitting it to the server. Hence, the code quoted above will
submit an empty value for "selected_group" regardless of what's actually
selected.


Bzzzt, sorry, this is incorrect. If no "value" clause is specified, the
text between <option> and </option> becomes the value for that item.
This is how you should do it:

<select name="selected_group">
<option value="Group 1">Group 1</option>
<option value="Group 2">Group 2</option>
</select>

This way, when the form is submitted, what you've defined in the
value-parameter is what is actually sent to the server.


Nope. The "value" clauses in your example are entirely unnecessary.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.