Jump to content

Passing Multiselect Data to PHP


princeofpersia

Recommended Posts

Hi guys,

 

I have a form with a multiselect option as below

 

       <select multiple="multiple" id="smoker" name="smoker[]">
               <option value="" selected="selected">Please select</option>      

<option value="No" >No</option>

<option value="Occasionally" >Occasionally</option>

<option value="Often" >Often</option>

<option value="Open to All" >Open to All</option>
   </select>

 

 

and need to pass this info into mysql insert, but before that I need them to be seperated by coma, i have the code below but keep getting errors

 

 

 


if ($_SERVER['REQUEST_METHOD'] == 'POST')	{
$smoker=stripslashes($_POST['smoker']);	
$smoker_db=implode(", ",$smoker);

}

 

 

this is the error i get

 

Notice: Array to string conversion in ......

 

Could you please help me with this?

 

Many thanks in advance :rtfm:

Link to comment
https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/
Share on other sites

if ($_SERVER['REQUEST_METHOD'] == 'POST')	{
    $smokers = $_POST["smoker"];
    if (is_array($smokers) & !empty($smokers)) {
        foreach ($smokers as &$smoker)
            $smoker = "'" . mysql_real_escape_string($smoker) . "'";	
        $smoker_db = implode(", ", $smokers);
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.