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 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); } } 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 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 .... 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. 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 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
Archived
This topic is now archived and is closed to further replies.