电子邮件更改数据未出现

时间:2019-07-08 19:01:22

标签: php jquery ajax

当我进行更新时,电子邮件数据不会出现,也不会进入数据库。

这是您要更改数据时的显示。

https://i.imgur.com/GuG0pT0.jpg

这是我进行更改后的显示,电子邮件没有进入数据库并且没有出现

https://i.imgur.com/vOkHAkI.jpg

这是用于更新文件siswa.php中的数据的代码

$(document).on('click', '.ubah_siswa', function() {
    siswa_id = $(this).attr('id');
    clear_field();
    $.ajax({
        url: "siswa_action.php",
        method: "POST",
        data: {
            action: 'edit_fetch',
            siswa_id: siswa_id
        },
        dataType: "json",
        success: function(data) {
            $('#nama_siswa').val(data.nama_siswa);
            $('#kelas_siswa').val(data.kelas_siswa);
            $('#siswa_peminatan_id').val(data.siswa_peminatan_id);
            $('#email_siswa').val(data.email_siswa);
            $('#error_foto_siswa').html('<img src="foto_siswa/' + data.foto_siswa + '" class="img-thumbnail" width="50" />');
            $('#hidden_foto_siswa').val(data.foto_siswa);
            $('#siswa_id').val(data.siswa_id);
            $('#modal_title').text("Ubah Data siswa");
            $('#button_action').val('Ubah');
            $('#action').val('Ubah');
            $('#formModal').modal('show');
        }
    });
});

这是用于更新文件siswa_action.php中的数据的代码

if ($_POST["action"] == "Ubah") {
    $data = array(
                ':nama_siswa'                =>    $nama_siswa,
                ':kelas_siswa'            =>    $kelas_siswa,
                ':siswa_peminatan_id'            =>    $siswa_peminatan_id,
                ':email_siswa'            =>    $email_siswa,
                ':foto_siswa'            =>    $foto_siswa,
                ':siswa_id'                =>    $_POST["siswa_id"]
            );
    $query = "UPDATE tbl_siswa 
                SET nama_siswa = :nama_siswa, 
                kelas_siswa = :kelas_siswa,
                foto_siswa = :foto_siswa, 
                email_siswa = :email_siswa, 
                siswa_peminatan_id = :siswa_peminatan_id
                WHERE siswa_id = :siswa_id
                ";
    $statement = $connect->prepare($query);
    if ($statement->execute($data)) {
        $output = array(
            'success'        =>    'Data Berhasil Diubah',
        );
    }
}

if ($_POST["action"] == "edit_fetch") {
    $query = "SELECT * FROM tbl_siswa WHERE siswa_id = '" . $_POST["siswa_id"] . "'";
    $statement = $connect->prepare($query);
    if ($statement->execute()) {
        $result = $statement->fetchAll();
        foreach ($result as $row) {
            $output['nama_siswa'] = $row['nama_siswa'];
            $output['kelas_siswa'] = $row['kelas_siswa'];
            $output['email_siswa'] = $row['email_siswa'];
            $output['siswa_peminatan_id'] = $row['siswa_peminatan_id'];
            $output['foto_siswa'] = $row['foto_siswa'];
            $output['siswa_id'] = $row['siswa_id'];
        }
        echo json_encode($output);
    }
}

有关完整代码,https://codesandbox.io/s/kind-dust-fjusz?fontsize=14

我尝试搜索出了什么问题,也许这里有人知道错误的地方,可以在完整的代码中查看详细信息

0 个答案:

没有答案