regoch Posted May 26, 2012 Share Posted May 26, 2012 Hi! I got this script for inserting jobs from multiple select, but can not get it work. I wonna all data from "select info_dodatni_posao" to get in one variable and put it in mysql database. I try this way thats below but not working! Any ideas? When I remove [] i get it to put just one job in mysql even if i select 3 or more. test.html <select multiple="multiple" name="info_dodatni_posao[]" id="info_dodatni_posao[]"> <option value='Certified Beauty Therapist'>Certified Beauty Therapist</option><option value='Certified Dive Master'>Certified Dive Master</option><option value='Certified Diver'>Certified Diver</option><option value='Certified Hair Dresser'>Certified Hair Dresser</option><option value='Certified Personal'>Certified Personal</option></select> test.php $info_id = $_POST['info_id']; $info_dodatni_posao = $_POST['info_dodatni_posao[]']; $qry = "UPDATE tz_info SET info_dodatni_posao='$info_dodatni_posao' WHERE info_id='$info_id'"; $result = @mysql_query($qry); Link to comment https://forums.phpfreaks.com/topic/263161-get-select-multiple-options-into-one-variable/ Share on other sites More sharing options...
Barand Posted May 26, 2012 Share Posted May 26, 2012 You should correctly normalise your tables and write a row for each selected item. But if you insist on storing multiple items you can use join() on the $_POST item to get a comma-separated list. Link to comment https://forums.phpfreaks.com/topic/263161-get-select-multiple-options-into-one-variable/#findComment-1348761 Share on other sites More sharing options...
regoch Posted May 26, 2012 Author Share Posted May 26, 2012 join() do the work! Thanks! Link to comment https://forums.phpfreaks.com/topic/263161-get-select-multiple-options-into-one-variable/#findComment-1348764 Share on other sites More sharing options...
thara Posted May 26, 2012 Share Posted May 26, 2012 hi... regoch.. how can we use join()... can you post your code to see us.. thank you.. Link to comment https://forums.phpfreaks.com/topic/263161-get-select-multiple-options-into-one-variable/#findComment-1348767 Share on other sites More sharing options...
regoch Posted May 26, 2012 Author Share Posted May 26, 2012 $info_id = $_POST['info_id']; $info_dodatni_posao = join(", ", $_POST['info_dodatni_posao']); $qry = "UPDATE tz_info SET info_dodatni_posao='$info_dodatni_posao' WHERE info_id='$info_id'"; $result = @mysql_query($qry); I add join() in second line and get all multiple post in one field in database with , between like this Full Time, Full Time Rotational, Freelance Link to comment https://forums.phpfreaks.com/topic/263161-get-select-multiple-options-into-one-variable/#findComment-1348772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.