Multiple Selection in to a MySQL table single row
Select all following options
Create table called "test1" in my_database
CREATE TABLE IF NOT EXISTS `test1` (
`test` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Creating fallowing php file you can insert data into mysql table as follows
<?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_database", $con); $test=$_POST['test']; $query="INSERT INTO test1 (test) VALUES ('".implode(',',$test)."')"; mysql_query($query) or die(mysql_error()); echo "Record is inserted"; ?> <form action="" 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> |
No comments:
Post a Comment