public function AddVideo() { $title = $_POST["videoTitle"]; $link = $_POST["videoLink"]; $description = $_POST["videoDescription"]; $video_id = Video::AddVideo($title, $link, $description); $arrayToInsert = array(); $count = 1; print_r($_POST); while (true) { if (isset($_POST["videoProductID" . $count])) { $txt = $_POST["videoProductID" . $count]; if ($txt != "---") { array_push($arrayToInsert, $txt); } } else { break; } $count++; } foreach ($arrayToInsert as $value) { Video::AddVideoProduct($video_id, $value); } }