我正在使用phpMyadmin和innoDb引擎。我已经完成了插入和删除。但是我什么也不能更新。我无法理解该错误。我从updatestudent.php调用了updatestudent。转到函数updatestudent,但它返回错误并且更新失败。

updateStudent.php
    

require_once '../includes/DbOperations.php';

$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){
    if(isset($_POST['name']) and isset($_POST['mobileno']) and isset($_POST['sem']) and isset($_POST['section']) and isset($_POST['usn'])){
        $db = new DbOperations();

        if($db->updateStudent($_POST['mobileno'], $_POST['sem'], $_POST['section'], $_POST['usn'])){
            $user = $db->getStudentByUsername($_POST['name']);
            $response['error'] = false;
            $response['name'] = $user['name'];
            $response['email'] = $user['email'];
            $response['mobileno'] = $user['mobileno'];
            $response['dept'] = $user['dept'];
            $response['sem'] = $user['sem'];
            $response['usn'] = $user['usn'];
            $response['section']=$user['section'];
        }else{
            $response['error'] = true;
            $response['message'] = "Update was not successful";
        }

    }else{
        $response['error'] = true;
        $response['message'] = "Required fields are missing";
    }
}

echo json_encode($response);


updateStudent函数

public function updateStudent($mobileno, $sem, $section, $usn){
            $stmt = $this->con->prepare("UPDATE `student` SET mobileno = ? AND sem = ? AND section = ? WHERE usn = ? ");
            $stmt->bind_param("ssss",$mobileno, $sem, $section, $usn);
            $stmt->execute();
            return $stmt->get_result();

        }

最佳答案

您的sql语句不正确:

应该

UPDATE `student` SET mobileno = ? AND sem = ? AND section = ? WHERE usn = ?

10-06 15:54