Hue_1 0 Newbie Poster

Hi all. I am having some trouble implementing my add-data.php as explained in this tutorial

My situation is that I should be able to do CRUD of data but from/to multiple tables. Following the tutorial, so far I have done the display/index.php, generate.php and the form part of add-data.php. Now, I'm stuck with the add-data.php, since everytime I add, only the second table "relation" receives input, the first one "trialindex2" does not insert my input.

Here's a part of my add-data.php:

<?php  
        if(isset($_POST['save_mul']))
        {  
                $total = $_POST['total'];

                for($i=1; $i<=$total; $i++)
                {
                // gets info from the add-data FORM
                $photo_link = mysqli_real_escape_string($_POST["photo_link$i"]); //mysqli_real_escape_string to prevent msyql injection
                $last_name = mysqli_real_escape_string($_POST["last_name$i"]);  //sanitize the input by using mysql_real_escape_string
                $first_name = mysqli_real_escape_string($_POST["first_name$i"]);
                $middle_name = mysqli_real_escape_string($_POST["middle_name$i"]);  
                $sex = mysqli_real_escape_string($_POST["sex$i"]);
                $vital_status = mysqli_real_escape_string($_POST["vital_status$i"]);
                $birth_date = mysqli_real_escape_string($_POST["birth_date$i"]);
                $birth_place = mysqli_real_escape_string($_POST["birth_place$i"]);
                $death_date = mysqli_real_escape_string($_POST["death_date$i"]);
                $death_place = mysqli_real_escape_string($_POST["death_place$i"]);
                $death_cause = mysqli_real_escape_string($_POST["death_cause$i"]);

                //query here   
                $query="INSERT INTO trialindex2 (photo_link, last_name, first_name, middle_name, sex, vital_status, birth_date,                          
                birth_place, death_date, death_place, death_cause)
                VALUES
        ('".$photo_link."','".$last_name."','".$first_name."','".$middle_name."','".$sex."','".$vital_status."','".$birth_date."','".$birth_place."','".$death_date."','".$death_place."',.'".$death_cause."')
                "; //closing for $query

                } //closing for for

                //$person_pk= mysql_insert_id($link);

                //check if query success
                if (mysqli_query($link,$query)) //$sql = $MySQLiconn->query($sql);
                {
                        //closing for php before if(isset)...
                        ?>             

                        <!--script to alert success/failure to insert-->
                        <script>
                        alert('<?php echo $total." new record(s) inserted !!!"; ?>');
                        window.location.href='./index.php';
                        </script>
                        <?php
                } //closing for if
                else
                {
                        //closing for else php
                        ?>  
                        <script>
                        alert('Error while inserting. TRY AGAIN!');
                        </script>
                <!--end of alert script-->

                <!--NOT SURE FOR POSITION-->           
                        <?php
                } //closing for else

                $last_insert_person_pk = mysql_insert_id();
                //get previous insert statement's person_pk

                //STORE RESULTS
                $result = mysqli_query("SELECT * FROM trialindex2 WHERE person_pk='$last_insert_person_pk'");

        } //closing for top if   //not sure for closing


?>