princeofpersia Posted May 17, 2012 Share Posted May 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/ Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/#findComment-1346331 Share on other sites More sharing options...
princeofpersia Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks i give it a try Quote Link to comment https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/#findComment-1346336 Share on other sites More sharing options...
princeofpersia Posted May 17, 2012 Author Share Posted May 17, 2012 This is what i get Warning: implode() [function.implode]: Invalid arguments passed in .... Quote Link to comment https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/#findComment-1346337 Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 Did you copy my code verbatim? My code above would not give that warning. Quote Link to comment https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/#findComment-1346338 Share on other sites More sharing options...
princeofpersia Posted May 17, 2012 Author Share Posted May 17, 2012 my mistake didnt get the difference woth smokers and smoker, its working now, thanks alot for ur help Quote Link to comment https://forums.phpfreaks.com/topic/262674-passing-multiselect-data-to-php/#findComment-1346340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.