插入带标题的多个图像

I need to insert multiple images with ad name every row. I am unable to insert ad name. I fail to modify the php code. There is no problem to insert multiple images. But problem comes when try to insert ad name with images. Plz help.

HTML

<form action="posting_ad_imagec.php" method="post" enctype="multipart/form-data">
Ad Title: <input type="text" id="ad_name" name="ad_name[]"/>
<input type="file" id="files" name="files[]" multiple="multiple" />
<input type="submit" name="submit" value="Submit">
</form>

PHP:

<?php

    $dir='ad/data/img/';

    if( isset( $_POST['submit'], $_FILES['files'] ) ) {

        $uploaded=array();
        $ad_names = $_POST["ad_name"];
        $sql = 'insert into `full texts` set `img_name` = ?, `img_type` = ?, `img_size` = ?, `ad_name` = ?';
        $stmt = $connection->prepare( $sql );


        if( $stmt ){

            $stmt->bind_param( 'ssss', $name, $type, $size, $ad_name);

            foreach( $_FILES['files']['name'] as $i => $name ) {
                if( !empty( $_FILES['files']['tmp_name'][$i] ) ) {

                    $name = $_FILES['files']['name'][$i];
                    $size = $_FILES['files']['size'][$i];
                    $type = $_FILES['files']['type'][$i];
                    $tmp  = $_FILES['files']['tmp_name'][$i];
                    $ad_name = $ad_names[$i];


                    if( is_uploaded_file( $tmp ) ){
                        $bytes = move_uploaded_file( $tmp, $dir.$name );
                        if( $bytes ){
                            $status = $stmt->execute();
                            $uploaded[]=$status && $bytes ? $name : false;
                        }
                    }
                }
            }
            if( !empty( $uploaded ) ){
                $_SESSION['s']=sprintf("%d images successfully saved", count( $uploaded ) );
                header('Location: posting_ad_image.php');
            }
        }
    }
?>

Step 1: Change name="ad_name[]" to name="ad_name" (no more brackets)
Step 2: Change $ad_names = $_POST["ad_name"]; to $ad_name = $_POST["ad_name"] (singular)
Step 3: Trash $ad_name = $ad_names[$i]; (no longer needed)