PHP无法写入Mysql数据库

时间:2019-07-12 13:04:44

标签: php mysql xampp

我尝试制作一个php代码以将一些文本输入写入数据库表,但是它什么也不能写。运行此代码时,看不到任何错误。我将localhost与xampp v3.2.3一起使用

这是我的数据库表结构

enter image description here

<?php
require_once("konek.php");

if(isset($_POST['submit'])){
    $nama_peminjam = 
filter_input(INPUT_POST,"nama_peminjam",FILTER_SANITIZE_STRING);
    $nomor_identitas = 
filter_input(INPUT_POST,"nomor_identitas",FILTER_SANITIZE_STRING);
    $nomor_telp = filter_input(INPUT_POST,"nomor_telp",FILTER_SANITIZE_STRING);
    $kode_inventaris = filter_input(INPUT_POST,"kode_inventaris",FILTER_SANITIZE_STRING);
    $jumlah = filter_input(INPUT_POST,"jumlah",FILTER_SANITIZE_STRING);
    $keperluan = filter_input(INPUT_POST,"keperluan",FILTER_SANITIZE_STRING);
    $tgl_pinjam = filter_input(INPUT_POST,"tgl_input",FILTER_SANITIZE_STRING);
    $tgl_balik = filter_input(INPUT_POST,"tgl_balik",FILTER_SANITIZE_STRING);
    $sts = filter_input(INPUT_POST,"status",FILTER_SANITIZE_STRING);
    $waktu_pinjam = filter_input(INPUT_POST,"waktu_pinjam",FILTER_SANITIZE_STRING);
    $waktu_balik = filter_input(INPUT_POST,"waktu_balik",FILTER_SANITIZE_STRING);


//query
    $sql = "INSERT INTO peminjaman 
                (nama_peminjam, nomor_identitas, nomor_telp, 
                kode_inventaris, jumlah, keperluan, tgl_pinjam, 
                waktu_pinjam, tgl_balik, waktu_balik, sts) 
        VALUES (:nama_peminjam, :nomor_identitas, :nomor_telp, 
                :kode_inventaris, :jumlah, :keperluan, :tgl_pinjam, 
                :waktu_pinjam, :tgl_balik, :waktu_balik, :sts)";

    $stmt = $db->prepare($sql);

    $sts2 = "0";

    $params = array(
        ":nama_peminjam" => $nama_peminjam,
        ":nomor_identitas" => $nomor_identitas,
        ":nomor_telp" => $nomor_telp,
        ":kode_inventaris" => $kode_inventaris,
        ":jumlah" => $jumlah,
        ":keperluan" => $keperluan,
        ":tgl_pinjam" => $tgl_pinjam,
        ":waktu_pinjam" => $waktu_pinjam,
        ":tgl_balik" => $tgl_balik,
        ":waktu_balik" => $waktu_balik,
        ":sts" => $sts2
    );
    $saved = $stmt->execute($params);

    if($saved){
        header("Location: index.php");
        exit;
    }
}
?>

浏览器未显示任何错误消息。

0 个答案:

没有答案