How to get multiple selected values of select box in php

Here we are explaing how to implement Multiple Select dropdown and how to get all the selected value of the select box and save it into the database.

Multiple Select dropdown is same like Simple dropdown box. The HTML code of both is same except Multiple Select dropdown need to write “multiple=”multiple”” in select option and important thing is we have added [] to the dropdown name ie skills[].

Here is the implementation HTML code of simple dropdown box.

<form method="post" name="SkillForm">
    <select id="skills" name="skills[]" multiple="multiple">
        <option value="HTML">HTML</option>
        <option value="HTML5">HTML5</option>
        <option value="CSS">CSS</option>
        <option value="CSS3">CSS3</option>
        <option value="JavaScript">JavaScript</option>
        <option value="PHP">PHP</option>
        <option value="MYSQL">MYSQL</option>
        <option value="WORDPRESS">WORDPRESS</option>
    </select>
    <input type="submit" name="SkillForm" value="Submit" />
</form>

Here is the PHP code for get value of simple multiple dropdown box and save into database.

<?php
if(isset($_POST['skills']))
{
    $skills = "";
    foreach($_POST['skills'] as $SkillValue)
    {
        $skills.= $SkillValue.", ";
    }
    echo $skills; // value of this variable you can into database
}
?>

		

Leave a Reply

Related Posts: You may like

How to remove whitespace from string using php

Remove All Special Characters From String PHP

Redirecting HTTP to HTTPS with PHP

Convert Base64 string to an image file

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.