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
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);
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.