Php 更新时未发送表单字段值

Php 更新时未发送表单字段值,php,mysql,Php,Mysql,我有一个表单,允许用户输入多个学生的分数,并指定记录分数的测试(test1、test2或test3)。我的查询的回音显示,只有第一行数据被发送到sql update语句,而其他数据似乎被截断(完全切断) 这是我的密码: <?php if (isset($_POST['submit'])) { # process the form $student_id = $_POST["student_id"]; $subject_id = $result['subject_i

我有一个表单,允许用户输入多个学生的分数,并指定记录分数的测试(test1、test2或test3)。我的查询的回音显示,只有第一行数据被发送到sql update语句,而其他数据似乎被截断(完全切断)

这是我的密码:

<?php
if (isset($_POST['submit'])) {

    # process the form
    $student_id = $_POST["student_id"];
    $subject_id = $result['subject_id'];
    $type = $_POST["type"];
    $score = $_POST["score"];

    for($i=0; $i < count($student_id); $i++) {
        $studentid = mysqli_real_escape_string($connection, $student_id[$i]);
        $subjectid = mysqli_real_escape_string($connection, $subject_id);
        $type = mysqli_real_escape_string($connection, $type);
        $score = mysqli_real_escape_string($connection, $score[$i]);

        $query = "UPDATE records SET $type='{$score}' WHERE student_id={$studentid} AND subject_id={$subjectid}";
        //$result = mysqli_query($connection, $query);
        echo $query;
    }
}
?>
还有下面的错误

注意:未初始化的字符串偏移量:第2行--$score=mysqli\u real\u escape\u字符串($connection,$score[$i])


为什么会发生这种情况?我如何修复这种情况?

您将覆盖数组$score。它应该是这样的:

$scoreOther = mysqli_real_escape_string($connection, $score[$i]);
然后将$scoreOther放入查询,而不是$score

$scoreOther = mysqli_real_escape_string($connection, $score[$i]);