Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get multiple values? 2

Status
Not open for further replies.

shaddow

Programmer
Mar 22, 2001
1,862
RO
How do i handle multiple values received from this code in the php part?

Code:
<select name=&quot;opt&quot; multiple>
  <option value=&quot;1&quot;>1
  <option value=&quot;2&quot;>2
  <option value=&quot;3&quot;>3
  <option value=&quot;4&quot;>4
  <option value=&quot;5&quot;>5
</select> ________
George, M
 
for php to know this is a multiple select (same goes for checkboxes with the same name) you need to add [] after the name of the field. you then get an array containing the values from the form.
for example:
Code:
<form>
<select name=&quot;opt[]&quot; multiple>
  <option value=&quot;1&quot;>1
  <option value=&quot;2&quot;>2
  <option value=&quot;3&quot;>3
  <option value=&quot;4&quot;>4
  <option value=&quot;5&quot;>5
</select>
<input type=submit>
</form>
<?
for ($i=0; $i < count($opt); $i++) {
	print $opt[$i].&quot;<br>\n&quot;;
}

?>
(-:
 
Thanks stakadush for your quick response... ________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top