Here is the database
CREATE TABLE IF NOT EXISTS `student` (
`id` int(11) NOT NULL,
`name` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `student`
ADD PRIMARY KEY (`id`);
ALTER TABLE `student`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Here is the HTML part: jsFiddle
And Here is the PHP part inserting data to mysql:
<?php
$connect = mysql_connect('localhost','root','');
if (!$connect) {
echo mysql_error();
}
$db = mysql_select_db('demo');
if (!$db) {
echo mysql_error();
}
$all_names ="";
if(isset($_POST["mytext"])){
foreach($_POST["mytext"] as $key => $text_field){
$all_names .= $text_field .", ";
}
}
$result = "INSERT INTO student ( name ) VALUES( $all_names )";
$insert_row = mysql_query($result);
if(!$insert_row){
echo $result;
}
Getting Error inserting value to database:
INSERT INTO student ( name ) VALUES( dffd, )