0

My html code is like below

 <select multiple="multiple" size="2" name="exServer[]">
 <option value="1"> host.newcybage.alabanza.com </option>
 <option value="2"> host2.newcybage.alabanza.com </option> 
 <option value="3"> host3.newcybage.alabanza.com </option> 
 <option value="5"> host3.devel.php5.qa.alabanza.com </option> 
 <option value="7"> centos5host2.alabanza.com </option> 
 <option value="8"> centos5host.template.alabanza.com </option> 
 </select>

<input type="submit" value="Apply" name="exSubmit" class="button">

And my php code is like below

$arr=$_POST['exServer'];
print_r($_POST['exServer']);
print_r($arr);

Both print statements are giving me no results. I dont know where i am wrong in getting selected multiple dropdown values.

I verified using HttpFox that data is getting posted properly on server side. When i am printing value of exSubmit, it is giving me proper values.

print "Exsubmit:".$_POST['exSubmit']; //Result Exsubmit:Apply

Please help.

nikhil
  • 21
  • 1
  • of course, besides from the missing form tags, did you pick any one those options? – Kevin Sep 16 '14 at 06:45
  • have you tried `$_POST['exServer[]']` ? – Himal Sep 16 '14 at 06:48
  • I have given form tag thats why i am getting correct values of exSubmit .Its just that i have not put it form tag here – nikhil Sep 16 '14 at 06:52
  • No Form tag? hahaha! That's it. – kimbarcelona Sep 16 '14 at 06:57
  • I tried print_r($POST); I m getting below result Array ( [exDay] => 01 [exMonth] => 09 [exYear] => 2014 [exDay2] => 16 [exMonth2] => 09 [exYear2] => 2014 [exServer] => [exSubmit] => Apply ) I getting all values except exServer – nikhil Sep 16 '14 at 07:03

2 Answers2

0

This should work

<select multiple="multiple" size="2" name="exServer[]">
 <option value="1"> host.newcybage.alabanza.com </option>
 <option value="2"> host2.newcybage.alabanza.com </option> 
 <option value="3"> host3.newcybage.alabanza.com </option> 
 <option value="5"> host3.devel.php5.qa.alabanza.com </option> 
 <option value="7"> centos5host2.alabanza.com </option> 
 <option value="8"> centos5host.template.alabanza.com </option> 
 </select>

My suggestion is to print the array $_POST and see the values passed in the backend.

<?php
print_r($_POST);
?>
kimbarcelona
  • 1,136
  • 2
  • 8
  • 19
  • nope dude, you need to set it as an array name if you want a multiple, `exServer[]`. [here](http://codepad.viper-7.com/0e630D) – Kevin Sep 16 '14 at 06:48
  • No while getting multiple selected values from dropdown we need put name as an array like i gave exServer[] – nikhil Sep 16 '14 at 06:50
  • Then, explain Alexandre Jasmin's answer here: http://stackoverflow.com/questions/2407284/how-to-get-multiple-selected-values-of-select-box-in-php – kimbarcelona Sep 16 '14 at 06:50
  • @kimbarcelona huh? that particular answer has this: ` – Kevin Sep 16 '14 at 06:54
  • Yeah, miseen that thing. Then I suppose nothing is wrong. Can you try to print_r($POST); and see what the output is? – kimbarcelona Sep 16 '14 at 06:55
  • ya dude that is what i am saying. I want multiple values that is why i have put name as an array like exServer[] – nikhil Sep 16 '14 at 06:56
  • I tried print_r($POST); I m getting below result Array ( [exDay] => 01 [exMonth] => 09 [exYear] => 2014 [exDay2] => 16 [exMonth2] => 09 [exYear2] => 2014 [exServer] => [exSubmit] => Apply ) I getting all values except exServer – nikhil Sep 16 '14 at 07:07
  • which comes first the form tag or the php code? can you give us more code? – kimbarcelona Sep 16 '14 at 07:09
0

you code is working. I tried this and got all the selected values in PHP

<?php
$arr=$_POST['exServer'];
print_r($_POST['exServer']);
print_r($arr);
?>

<form method="post">

    <select multiple="multiple" size="2" name="exServer[]">
 <option value="1"> host.newcybage.alabanza.com </option>
 <option value="2"> host2.newcybage.alabanza.com </option> 
 <option value="3"> host3.newcybage.alabanza.com </option> 
 <option value="5"> host3.devel.php5.qa.alabanza.com </option> 
 <option value="7"> centos5host2.alabanza.com </option> 
 <option value="8"> centos5host.template.alabanza.com </option> 
 </select>

<input type="submit" value="Apply" name="exSubmit" class="button">


</form>
Maz I
  • 3,664
  • 2
  • 23
  • 38