当我尝试在SQL PHP中使用WHERE变量时,它不起作用

当我尝试在SQL PHP中使用WHERE变量时,它不起作用,php,sql,variables,sql-update,where-clause,Php,Sql,Variables,Sql Update,Where Clause,这是我的一段代码,我试图用where编辑一条记录。当我手动输入id号时,它会编辑记录并显示记录已成功更新。当我使用上一页中的变量时,记录显示记录已成功更新,但未更改我的记录 这在我手动输入要编辑的ID时起作用 // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->co

这是我的一段代码,我试图用where编辑一条记录。当我手动输入id号时,它会编辑记录并显示记录已成功更新。当我使用上一页中的变量时,记录显示记录已成功更新,但未更改我的记录

这在我手动输入要编辑的ID时起作用

// Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

            $student_ID = $_GET{'student_ID'};

            $sql =  "UPDATE student_info_2020 SET student_first_name = '$student_first_name', student_last_name = '$student_last_name', student_username = '$student_username',student_password = '$student_password',
            student_program = '$student_program', student_portfolio = '$student_portfolio', student_linkedin = '$student_linkedin', student_secondary = '$student_secondary', student_hometown = '$student_hometown',
            student_career_goals = '$student_career_goals', student_hobbies = '$student_hobbies', student_state = '$student_state' WHERE student_ID = 2";


        if ($conn->query($sql) === TRUE) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . $conn->error;
        }

    $conn->close();
当我尝试为WHERE子句使用变量时,它不起作用。我回显了$student_ID,找到了一个正确的数字,是2,但没有编辑记录2。它还报告记录已成功更新,但没有更新,因此我相当困惑

// Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

            $student_ID = $_GET{'student_ID'};

            $sql =  "UPDATE student_info_2020 SET student_first_name = '$student_first_name', student_last_name = '$student_last_name', student_username = '$student_username',student_password = '$student_password',
            student_program = '$student_program', student_portfolio = '$student_portfolio', student_linkedin = '$student_linkedin', student_secondary = '$student_secondary', student_hometown = '$student_hometown',
            student_career_goals = '$student_career_goals', student_hobbies = '$student_hobbies', student_state = '$student_state' WHERE student_ID = '$student_ID'";


        if ($conn->query($sql) === TRUE) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . $conn->error;
        }

    $conn->close();
使用[和]从$\u GET数组获取值:

尝试使用sprintf

$sql =  sprintf("UPDATE student_info_2020 SET student_first_name = '$student_first_name', student_last_name = '$student_last_name', student_username = '$student_username',student_password = '$student_password',
        student_program = '$student_program', student_portfolio = '$student_portfolio', student_linkedin = '$student_linkedin', student_secondary = '$student_secondary', student_hometown = '$student_hometown',
        student_career_goals = '$student_career_goals', student_hobbies = '$student_hobbies', student_state = '$student_state' WHERE student_ID = %d",(int)$student_ID);

那也没用。我不明白为什么我在这里面手动输入一个数字是如此令人沮丧的lol。同一个项目的另一个例子$stmt=$conn->prepareSELECT student_password from student_info_2020,其中student_username='$inName';不起作用,但这可以$stmt=$conn->Prepare从student_info_2020中选择student_密码,其中student_用户名=moonman;
$sql =  sprintf("UPDATE student_info_2020 SET student_first_name = '$student_first_name', student_last_name = '$student_last_name', student_username = '$student_username',student_password = '$student_password',
        student_program = '$student_program', student_portfolio = '$student_portfolio', student_linkedin = '$student_linkedin', student_secondary = '$student_secondary', student_hometown = '$student_hometown',
        student_career_goals = '$student_career_goals', student_hobbies = '$student_hobbies', student_state = '$student_state' WHERE student_ID = %d",(int)$student_ID);