Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从它所属的元素PHP获取id_Php_Foreach - Fatal编程技术网

从它所属的元素PHP获取id

从它所属的元素PHP获取id,php,foreach,Php,Foreach,我试图从字幕文件所属的元素中获取id,如何组合foreach$\u POST和foreach$\u文件以便获取id 以下是我的php代码: foreach ($_POST['episodes'] as $episodes => $value ) { $episode_title = $value['episode_title']; $sql_episode = "INSERT INTO episode VALUES ('', '$episode_title', 'description',

我试图从字幕文件所属的元素中获取id,如何组合foreach$\u POST和foreach$\u文件以便获取id

以下是我的php代码:

foreach ($_POST['episodes'] as $episodes => $value ) {
$episode_title = $value['episode_title'];
$sql_episode = "INSERT INTO episode VALUES ('', '$episode_title', 'description', '1')";
    if ($db->query($sql_episode) === TRUE) {

        $inserted_id_episodes = $db->insert_id;

        if (isset($value['subtitle'])) {
            foreach ($value['subtitle'] as $subtitle) {
              $language = $subtitle['language'];
              $sql_subtitle = "INSERT INTO added_subtitle VALUES ('', '$language', 'path', '$inserted_id_episodes')";
                if ($db->query($sql_subtitle) === TRUE) {
                    $inserted_id_subtitle = $db->insert_id; //this is the id I want to get.

                    if(!empty($_FILES['subtitlePath'])){
                        foreach($_FILES['subtitlePath']['tmp_name'] as $key => $tmp_name){
                            $file_name = $key.$_FILES['subtitlePath']['name'][$key];
                            $file_size = $_FILES['subtitlePath']['size'][$key];
                            $file_tmp = $_FILES['subtitlePath']['tmp_name'][$key];
                            $file_type = $_FILES['subtitlePath']['type'][$key];
                            $fileInfo = pathinfo($_FILES["subtitlePath"]["name"][$key]);
                            $target_dir = "../images/covers/";
                            $target_file = $target_dir . $file_name;
                            move_uploaded_file($file_tmp, $target_file);
                            $sql_subtitlePath = "UPDATE added_subtitle SET  subtitle_path = '$target_file' WHERE ID = '$inserted_id_subtitle'"; // I wan't to update the table with that inserted id 
                            $result = $db->query($sql_subtitlePath);
                        }
                    }

                }
            }
        }
    }
}
HTML


我希望有人能帮我做这件事,那么如何组合foreach$\u POST和foreach$\u文件。谢谢

您的多个subtitlePath[3]字段相互覆盖。很抱歉,这是一个错误,当我使用javascript添加它们并给出数字时,它会得到一个新的数字。
<form  action="" method="post">

<input type="text" name="episodes[0][episode_title]" value="">

<input type="text" name="episodes[0][subtitle][0][language]" value="">
<input type="file" name="subtitlePath[3]" value="">

<input type="text" name="episodes[0][subtitle][1][language]" value="">
<input type="file" name="subtitlePath[3]" value="">

<input type="text" name="episodes[1][episode_title]" value="">

<input type="text" name="episodes[1][subtitle][0][language]" value="">
<input type="file" name="subtitlePath[3]" value="">


</form>