Raja Tayyab
Raja Tayyab

Reputation: 59

I want to add the dropdown value to mysql and save it

I just want to add my dropdown values in mysql

i tried a lot of things but every time my localhost shows validation error or not adding my data

My view

<label for="rank_restriction">Rank Restriction</label>

<select  class="chosen-select" multiple="" id="ristrict" name="ristrict">
<?php foreach ($poll['rankname'] as $rank) {?>
<option value=""><?= $rank ?></option>
 <?php } ?>
 </select>

And i am not sure what to do in controller please guide me

Upvotes: 1

Views: 52

Answers (1)

Lets-c-codeigniter
Lets-c-codeigniter

Reputation: 714

1) If you are using select tag with multiple attribute, Use tag name as name="ristrict[]".

2) And you can get selected options with $_POST['ristrict']

3) $_POST['ristrict'] is array that contains selected options.

Here is the below complete code

<label for="rank_restriction">Rank Restriction</label>
<select  class="chosen-select" multiple="multiple" id="ristrict" name="ristrict[]">
    <?php foreach ($poll['rankname'] as $rank) 
    {?>
        <option value="<?php echo $rank; ?>"><?php echo $rank; ?></option>
    <?php 
    } ?>
</select>

4) You can get selected options like this

$ristricts = $_POST['ristrict'];
foreach($ristricts as $ristrict)
{
    //Your logic here....
}

Upvotes: 1

Related Questions