I am a beginner in PHP.I am stuck with a problem. The idea is that I have to assign actors to a selected movie and add a role for each. I need to pick several values from the list and add a description for each via texfields. My code adds all the checked values to the database, but it makes a mess with the values from the textfields, the checked values don't match with the description. I would be really grateful for your help! My code: Form:
<?php
$sqlquery = "SELECT artistId, firstname, lastname from $artists order by 2";
$result = mysqli_query($connect, $sqlquery);
if($result) {
    echo "<table class=\"addactor\">";
    echo "<tr>
        <td id=\"text\" colspan=\"2\"><h3>Assign an actor to the movie</h3></td>
    </tr>";
    while($sqlRow = mysqli_fetch_array($result, MYSQL_ASSOC)) {
        echo "<tr>";
        echo "<td>";
        echo "<input type=\"checkbox\" name=\"checkbox[]\" value=\"" . $sqlRow['artistId'] . "\"/> " . $sqlRow['firstname'] . " " . $sqlRow['lastname'] . "</td><td><input type=\"text\" name=\"textbox[]\"/></td>";
        echo "</tr>";
    }
    echo "<tr><td align=\"right\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Add\"></td><td><input type=\"reset\" name=\"reset\" id=\"reset\" value=\"Reset\"></td></tr></table>;";
}
print '</table>';
The connection to the database is in another file, which is included here.
The second part:
if($_POST) {
        $checkbox = $_POST['checkbox'];
        $txt = $_POST['textbox'];
        $len = sizeof($checkbox);
        for($i = 0; $i < $len; $i++) {
            $sqlqr = "INSERT INTO $role (artistId, movieCode, Description) VALUES ('" . $checkbox[$i] . "', '" . $_POST['moviecode'] . "', '" . $txt[$i] . "')";
            mysqli_query($connect, $sqlqr);
        }
        $query = "INSERT INTO $movies(movieCode, title, dateOfIssue,category, description, image) VALUES ('" . $_POST['moviecode'] . "', '" . $_POST['title'] . "', '" . $_POST['dateofissue'] . "','" . $_POST['category'] . "', '" . $_POST['desc'] . "', '" . $_POST['image1'] . "')";
        mysqli_query($connect, $query);
        if(mysqli_query($connect, $query) || mysqli_query($connect, $sqlqr)) {
            echo "<h4>1 record added</h4>";
        }
        else {
            die('Error: ' . mysqli_error($connect));
        }
        print '</form>';
    }
 
     
     
     
     
    