anshuverma1989 Posted February 11, 2009 Share Posted February 11, 2009 Hey people.. I have this hobby listbox with up to near about 15 items where a user can select multiple item. How can i insert all the items selected in the listbox? Example Hobbies: If multiple hobbies are selected in the listbox and on press button how should i insert into database? I saw this tutorial on the website.. in which .. if one item is select it will save one item only and if multiple item is selected, it puts "," between the items selected and then save into database. but i cannot find it rite now.. so please help me .. how can i do it?? Quote Link to comment https://forums.phpfreaks.com/topic/144791-listbox-to-database/ Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 Page: test.php <?php if (isset($_POST['list']) && is_array($_POST['list'])) { $items = implode(", ", $_POST['list']); echo $items; } ?> <form action="test.php" method="POST"> <select size="4" name="list[]" multiple> <option value="1">Item 1</option> <option value="2">Item 2</option> <option value="3">Item 3</option> <option value="4">Item 4</option> </select> <input type="submit" value="submit" /> </form> Should do it, making the name of the select an array (adding the []) allows for you to post more than one element. Using the implode on that posted item will make it into one line, comma separated. Quote Link to comment https://forums.phpfreaks.com/topic/144791-listbox-to-database/#findComment-759807 Share on other sites More sharing options...
anshuverma1989 Posted February 11, 2009 Author Share Posted February 11, 2009 Hey.. thanks alot.. you actually saved my day.. thanks again .. the problem got soved.. thanks again.. Quote Link to comment https://forums.phpfreaks.com/topic/144791-listbox-to-database/#findComment-759810 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.