pahunrepublic Posted July 22, 2010 Share Posted July 22, 2010 I know it's maybe EASY but how can I insert datas into database from multi-select html form? Here is the code: <body><form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form> <?php $test=$_POST['test']; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } ?></body> Any ideas how to modify the above code so I can INSERT INTO values from multi-select box? Link to comment https://forums.phpfreaks.com/topic/208498-insert-into-database-multiselect-box-values/ Share on other sites More sharing options...
vichu.1985 Posted July 28, 2010 Share Posted July 28, 2010 try with php code <?php $test=$_POST['test']; $result = ''; if ($test){ foreach ($test as $t){ $result .= $t.','; } $result = trim($result, ','); } // write ur insert query with $result variable ?> Link to comment https://forums.phpfreaks.com/topic/208498-insert-into-database-multiselect-box-values/#findComment-1092047 Share on other sites More sharing options...
pahunrepublic Posted July 30, 2010 Author Share Posted July 30, 2010 try with php code <?php $test=$_POST['test']; $result = ''; if ($test){ foreach ($test as $t){ $result .= $t.','; } $result = trim($result, ','); } // write ur insert query with $result variable ?> I tried the your code vichu.1985. The problem is with this code, it only inserts the last selected item into database. But the problem is solved above this topic: http://www.phpfreaks.com/forums/index.php/topic,305122.msg1442995.html#msg1442995 ut THANX anyway Link to comment https://forums.phpfreaks.com/topic/208498-insert-into-database-multiselect-box-values/#findComment-1092902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.