IT & Programming

Working with listbox and php

  • ow to process listbox or multiple select box with php.
  • How to get listbox values with php.
  • Working with php and multiple value select box.

This script process listbox values sent from a form. We have 2 php pages. At Forms.php we have a form with listbox and a submit a button. Once we click submit button after selecting few values, the page submits values to Save.php. Then we get all listbox selected value with the help of for loop.

Form.php

<form action="Save.php" method="post">

	<select multiple="multiple" name="country[]">< /option>
		<option value="Belgium">Belgium< /option>
		<option value="France">France< /option>
		<option value="Germany">Germany< /option>
		<option value="Holland">Holland< /option>
		<option value="Greece">Greece< /option>
	</select>
	<input value="Submit" type="Submit" />

</form>

Save.php

if(!empty($_POST['country'])){

	for ($i=0; $i < count($_POST['country']);$i++) {
		echo $_POST['country'][$i] . ", ";
	}
}

Output

Belgium, Germany,

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *