Assuming the value at indexes is related for course/topic/parent, etc. You can skip one of the for loops too.
if(isset($_POST['submitmultiple']))
{
$course_id = $_POST['course_id'];
$topic_name = $_POST['topic_name'];
$topic_description = $_POST['topic_description'];
$parent_id = $_POST['parent_id'];
echo count($course_id);
if(!empty($course_id))
{
foreach ($_POST['course_id'] as $key => $value)
{
$tempcourse_id = $course_id[$key];
$temptopic_name = $topic_name[$key];
$temptopic_description = $topic_description[$key];
$tempparent_id = $parent_id[$key];
$sql = "INSERT INTO syllabus (course_id,topic_name,topic_description,parent_id) VALUES ('$tempcourse_id','$temptopic_name','$temptopic_description','$tempparent_id')";
//Verify the query formed
echo $sql."\n";
if($connect->query($sql) === TRUE)
{
$valid[1] = "Added Successfully";
}
else
{
$valid[2] = "Error while Inserting";
}
}
}
}
manpreet
Best Answer
2 years ago
Insert HTML Form array into database rows in mySQL with PHP i am inserting html array into database using for and foreach problem inserting data in to database using for loop its inserting blank data please help. please give advice on it or give solution thank you in advance i have tried the below code or any different method using for it.
php file
html code