Tolong bantu saya, tidak dapat insert ke database

<?php include "../Database/config/+koneksi.php"; require_once ('../Database/models/database.php'); include "../Database/models/m_teknisi2.php"; //require 'functions2.php'; $connection = new Database($host, $user, $pass, $database); $tkns2 = new Teknisi2($connection); ob_start();

//if (tambahtkns($_POST) &gt; 0) {
//}else {
   // echo &quot;data gagal ditambahkan!&quot;;
//}

?> <!DOCTYPE html> <html lang="en"> <head> <link type="text/css" rel="stylesheet" href="Halaman registrasi teknisi2/css/Style halaman registrasi teknisi2.css"/>

    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;!--Let.browser.know.website.is.optimized.for.mobile--&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.googleapis.com&quot;&gt;
    &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.gstatic.com&quot; crossorigin/&gt;
    &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
    &lt;script src=&quot;https://kit.fontawesome.com/c4254e24a8.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://code.jquery.com/jquery-3.7.1.js&quot;&gt;&lt;/script&gt;
    &lt;title&gt;SERVAILD&lt;/title&gt;
&lt;/head&gt; 
&lt;body&gt;
    &lt;!-- Header Menggunakan Metode CSS GRID --&gt;
    &lt;div class=&quot;header-wrapper&quot;&gt;
        &lt;!-- PEMBUKA KOLOM KIRI --&gt; 
        &lt;div class=&quot;logo-wrapper left center&quot;&gt;
            &lt;a href=&quot;../Halaman depan/Halaman depan.php&quot;&gt;&lt;img src=&quot;../../Halaman depan/img/servaild_logo-long_white.png&quot;&gt;&lt;/a&gt;
        &lt;/div&gt;
        &lt;!-- PENUTUP KOLOM BAGIAN KIRI --&gt;
        &lt;!-- PEMBUKA KOLOM KANAN --&gt;
        &lt;div class=&quot;navlink-wrapper right&quot;&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div   &gt; 
        &lt;!-- PENUTUP KOLOM KANAN --&gt;
    &lt;/div&gt;

    &lt;!-- FORM REGISTRASI USER--&gt;
    &lt;div class=&quot;content&quot;&gt;
        &lt;section class=&quot;container-form&quot;&gt;
            &lt;header&gt;Silahkan Registrasi&lt;/header&gt;
            &lt;?php 
            global $conn;
            if ( isset($_POST[&quot;submit&quot;]) ) {
                if (tambahtkns2($_POST) &gt; 0) {
                    echo &#039;&lt;p class=&quot;berhasil&quot;&gt;Data berhasil ditambahkan!&lt;/p&gt;&#039;;
                } else {
                    echo &#039;&lt;p class=&quot;error&quot;&gt;Data gagal ditambahkan!&lt;/p&gt;&#039;;
                }
            }
            ?&gt;
            &lt;form action=&quot;&quot; class=&quot;form&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
                &lt;div class=&quot;input-box address&quot;&gt;
                    &lt;label&gt;Alamat&lt;/label&gt;
                    &lt;input type=&quot;text&quot; name=&quot;almt&quot; id=&quot;almt&quot; for=&quot;almt&quot; placeholder=&quot;Masukkan alamat&quot; required /&gt;
                    &lt;div class=&quot;column&quot;&gt;
                        &lt;div class=&quot;select-box&quot;&gt;
                            &lt;select name=&quot;negara&quot; id=&quot;negara&quot;&gt;
                                &lt;option hidden&gt;Negara&lt;/option&gt;
                                &lt;option&gt;Indonesia&lt;/option&gt;
                                &lt;option&gt;Amerika&lt;/option&gt;
                                &lt;option&gt;Japan&lt;/option&gt;
                                &lt;option&gt;India&lt;/option&gt;
                            &lt;/select&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;select-box&quot;&gt;
                            &lt;select name=&quot;kota&quot; id=&quot;kota&quot; &gt;
                                &lt;option hidden&gt;Kota&lt;/option&gt;
                                &lt;option&gt;Bandung&lt;/option&gt;
                                &lt;option&gt;Bogor&lt;/option&gt;
                                &lt;option&gt;Banda Aceh&lt;/option&gt;
                                &lt;option&gt;Langsa&lt;/option&gt;
                                &lt;option&gt;Lhokseumawe&lt;/option&gt;
                                &lt;option&gt;Sabang&lt;/option&gt;
                                &lt;option&gt;Subulussalam&lt;/option&gt;
                                &lt;option&gt;Denpasar&lt;/option&gt;
                                &lt;option&gt;Pangkalpinang&lt;/option&gt;
                                &lt;option&gt;Cilegon&lt;/option&gt;
                                &lt;option&gt;Serang&lt;/option&gt;
                                &lt;option&gt;Tangerang Selatan&lt;/option&gt;
                                &lt;option&gt;Tangerang&lt;/option&gt;
                                &lt;option&gt;Bengkulu&lt;/option&gt;
                                &lt;option&gt;Yogyakarta&lt;/option&gt;
                                &lt;option&gt;Gorontalo&lt;/option&gt;
                                &lt;option&gt;Kota Administrasi Jakarta Barat&lt;/option&gt;
                                &lt;option&gt;Kota Administrasi Jakarta Pusat&lt;/option&gt;
                                &lt;option&gt;Kota Administrasi Jakarta Selatan&lt;/option&gt;
                                &lt;option&gt;Kota Administrasi Jakarta Timur&lt;/option&gt;
                                &lt;option&gt;Kota Administrasi Jakarta Utara&lt;/option&gt;
                                &lt;option&gt;Sungai Penuh&lt;/option&gt;
                                &lt;option&gt;Jambi&lt;/option&gt;
                                &lt;option&gt;Bekasi&lt;/option&gt;
                                &lt;option&gt;Cimahi&lt;/option&gt;
                                &lt;option&gt;Cirebon&lt;/option&gt;
                                &lt;option&gt;Depok&lt;/option&gt;
                                &lt;option&gt;Sukabumi&lt;/option&gt;
                                &lt;option&gt;Tasikmalaya&lt;/option&gt;
                                &lt;option&gt;Banjar&lt;/option&gt;
                                &lt;option&gt;Magelang&lt;/option&gt;
                                &lt;option&gt;Pekalongan&lt;/option&gt;
                                &lt;option&gt;Salatiga&lt;/option&gt;
                                &lt;option&gt;Semarang&lt;/option&gt;
                                &lt;option&gt;Surakarta&lt;/option&gt;
                                &lt;option&gt;Tegal&lt;/option&gt;
                                &lt;option&gt;Batu&lt;/option&gt;
                                &lt;option&gt;Blitar&lt;/option&gt;
                                &lt;option&gt;Kediri&lt;/option&gt;
                                &lt;option&gt;Madiun&lt;/option&gt;
                                &lt;option&gt;Malang&lt;/option&gt;
                                &lt;option&gt;Mojokerto&lt;/option&gt;
                                &lt;option&gt;Pasuruan&lt;/option&gt;
                                &lt;option&gt;Probolinggo&lt;/option&gt;
                                &lt;option&gt;Surabaya&lt;/option&gt;
                                &lt;option&gt;Pontianak&lt;/option&gt;
                                &lt;option&gt;Singkawang&lt;/option&gt;
                                &lt;option&gt;Banjarbaru&lt;/option&gt;
                                &lt;option&gt;Banjarmasin&lt;/option&gt;
                                &lt;option&gt;Palangka Raya&lt;/option&gt;
                                &lt;option&gt;Balikpapan&lt;/option&gt;
                                &lt;option&gt;Bontang&lt;/option&gt;
                                &lt;option&gt;Samarinda&lt;/option&gt;
                                &lt;option&gt;Nusantara&lt;/option&gt;
                                &lt;option&gt;Tarakan&lt;/option&gt;
                                &lt;option&gt;Batam&lt;/option&gt;
                                &lt;option&gt;Tanjungpinang&lt;/option&gt;
                                &lt;option&gt;Bandar Lampung&lt;/option&gt;
                                &lt;option&gt;Metro&lt;/option&gt;
                                &lt;option&gt;Ternate&lt;/option&gt;
                                &lt;option&gt;Tidore Kepulauan&lt;/option&gt;
                                &lt;option&gt;Ambon&lt;/option&gt;
                                &lt;option&gt;Tual&lt;/option&gt;
                                &lt;option&gt;Bima&lt;/option&gt;
                                &lt;option&gt;Mataram&lt;/option&gt;
                                &lt;option&gt;Kupang&lt;/option&gt;
                                &lt;option&gt;Sorong&lt;/option&gt;
                                &lt;option&gt;Jayapura&lt;/option&gt;
                                &lt;option&gt;Dumai&lt;/option&gt;
                                &lt;option&gt;Pekanbaru&lt;/option&gt;
                                &lt;option&gt;Makassar&lt;/option&gt;
                                &lt;option&gt;Palopo&lt;/option&gt;
                                &lt;option&gt;Palu&lt;/option&gt;
                                &lt;option&gt;Baubau&lt;/option&gt;
                                &lt;option&gt;Kendari&lt;/option&gt;
                                &lt;option&gt;Bitung&lt;/option&gt;
                                &lt;option&gt;Kotamobagu&lt;/option&gt;
                                &lt;option&gt;Manado&lt;/option&gt;
                                &lt;option&gt;Tomohon&lt;/option&gt;
                                &lt;option&gt;Bukittinggi&lt;/option&gt;
                                &lt;option&gt;Padang&lt;/option&gt;
                                &lt;option&gt;Padang Panjang&lt;/option&gt;
                                &lt;option&gt;Pariaman&lt;/option&gt;
                                &lt;option&gt;Payakumbuh&lt;/option&gt;
                                &lt;option&gt;Sawahlunto&lt;/option&gt;
                                &lt;option&gt;Solok&lt;/option&gt;
                                &lt;option&gt;Lubuklinggau&lt;/option&gt;
                                &lt;option&gt;Pagar Alam&lt;/option&gt;
                                &lt;option&gt;Palembang&lt;/option&gt;
                                &lt;option&gt;Prabumulih&lt;/option&gt;
                                &lt;option&gt;Binjai&lt;/option&gt;
                                &lt;option&gt;Gunungsitoli&lt;/option&gt;
                                &lt;option&gt;Medan&lt;/option&gt;
                                &lt;option&gt;Padangsidimpuan&lt;/option&gt;
                                &lt;option&gt;Pematangsiantar&lt;/option&gt;
                                &lt;option&gt;Sibolga&lt;/option&gt;
                                &lt;option&gt;Tanjungbalai&lt;/option&gt;
                                &lt;option&gt;Tebing Tinggi&lt;/option&gt;
                            &lt;/select&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;column&quot;&gt;
                        &lt;input type=&quot;number&quot; name=&quot;kode_pos&quot; id=&quot;kode_pos&quot; for=&quot;kode_pos&quot; placeholder=&quot;Masukkan kode pos&quot; required minlength=&quot;4&quot; maxlength=&quot;12&quot;/&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;input-box&quot;&gt;
                    &lt;label&gt;Nomor Induk Berusaha&lt;/label&gt;
                    &lt;input type=&quot;number&quot; name=&quot;nib&quot; for=&quot;nib&quot; id=&quot;nib&quot; placeholder=&quot;Masukkan nomor induk berusaha&quot; minlength=&quot;4&quot; maxlength=&quot;12&quot; required&gt;
                &lt;/div&gt;

                &lt;div class=&quot;input-box&quot;&gt;
                    &lt;label&gt;Nomor Rekening&lt;/label&gt;
                    &lt;input type=&quot;number&quot; name=&quot;no_rek&quot; id=&quot;no_rek&quot; for=&quot;no_rek&quot; placeholder=&quot;Masukkan nomor rekening&quot; minlength=&quot;4&quot; maxlength=&quot;12&quot; required&gt;
                    &lt;img src=&quot;../Halaman depan/img/card_img.png&quot; alt=&quot;&quot;&gt;
                &lt;/div&gt;

                &lt;div class=&quot;docx&quot;&gt;
                    &lt;label class=&quot;control-label sc_surat_perjanjian_krjsm&quot; for=&quot;sc_surat_perjanjian_krjsm&quot;&gt;Surat Perjanjian Kerjasama&lt;/label&gt;
                    &lt;button class=&quot;btn-sc-perjanjian-krjsm&quot; onclick=&quot;location.href=&#039;../Halaman registrasi teknisi/Halaman registrasi teknisi2/docx/SURAT PERJANJIAN KERJASAMA.docx&#039;;&quot;&gt; Unduh Surat Perjanjian Kerjasama&lt;/button&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;control-label sc_akta_kelahiran&quot; for=&quot;sc_akta_kelahiran&quot;&gt;Scan Akta Kelahiran&lt;/label&gt;
                    &lt;div style=&quot;padding-bottom:5px&quot;&gt;
                    &lt;embed src=&quot;&quot; type=&quot;application/pdf&quot; width=&quot;100%&quot; height=&quot;10px&quot;&gt;
                    &lt;/div&gt;
                    &lt;input style=&quot;margin-left: 0px; margin-top: 0px;&quot;type=&quot;file&quot; name=&quot;sc_akta_kelahiran&quot; class=&quot;form-control&quot; id=&quot;sc_akta_kelahiran&quot;&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;control-label sc_kk&quot; for=&quot;sc_kk&quot;&gt;Scan Kartu Keluarga&lt;/label&gt;
                    &lt;div style=&quot;padding-bottom:5px&quot;&gt;
                    &lt;embed src=&quot;&quot; type=&quot;application/pdf&quot; width=&quot;100%&quot; height=&quot;10px&quot;&gt;
                    &lt;/div&gt;
                    &lt;input style=&quot;margin-left: 40px;&quot;type=&quot;file&quot; name=&quot;sc_kk&quot; class=&quot;form-control&quot; id=&quot;sc_kk&quot;&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;control-label sc_ktp&quot; for=&quot;sc_ktp&quot;&gt;Scan Kartu Tanda Penduduk&lt;/label&gt;
                    &lt;div style=&quot;padding-bottom:5px&quot;&gt;
                    &lt;embed src=&quot;&quot; type=&quot;application/pdf&quot; width=&quot;100%&quot; height=&quot;10px&quot;&gt;
                    &lt;/div&gt;
                    &lt;input type=&quot;file&quot; name=&quot;sc_ktp&quot; class=&quot;form-control&quot; id=&quot;sc_ktp&quot;&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;control-label&quot; for=&quot;sc_perjanjian_krjsm&quot;&gt;Scan Surat Perjanjian Kerjasama&lt;/label&gt;
                    &lt;div style=&quot;padding-bottom:5px&quot;&gt;
                    &lt;embed src=&quot;&quot; type=&quot;application/pdf&quot; width=&quot;100%&quot; height=&quot;10px&quot;&gt;
                    &lt;/div&gt;
                    &lt;input style=&quot;margin-left:40px;&quot;type=&quot;file&quot; name=&quot;sc_perjanjian_krjsm&quot; class=&quot;form-control&quot; id=&quot;sc_perjanjian_krjsm&quot;&gt;
                &lt;/div&gt;
                &lt;div&gt;
                &lt;button class=&quot;konfirmasi&quot; type=&quot;submit&quot; name=&quot;submit&quot;&gt;Konfirmasi&lt;/button&gt;
                &lt;/div&gt;
            &lt;/form&gt;
            &lt;?php 
            function tambahtkns2($data) {
                    global $conn;
                    $almt = htmlspecialchars($data[&quot;almt&quot;]);
                    $negara = $_POST[&quot;negara&quot;];
                    $kota = $_POST[&quot;kota&quot;];
                    $kode_pos = htmlspecialchars($data[&quot;kode_pos&quot;]);
                    $nib = htmlspecialchars($data[&quot;nib&quot;]);
                    $no_rek = htmlspecialchars($data[&quot;no_rek&quot;]);
                
                if (@$_POST[&#039;submit&#039;]) {
                    
                    $ekstensiakta = explode(&quot;.&quot;, $_FILES[&#039;sc_akta_kelahiran&#039;][&#039;name&#039;]);
                    $sc_akta_kelahiran = &quot;akta kelahiran-&quot;.round(microtime(true)).&quot;.&quot;.end($ekstensiakta);
                    $sumberakta = $_FILES[&#039;sc_akta_kelahiran&#039;][&#039;tmp_name&#039;];
                    
                    $uploadakta = move_uploaded_file($sumberakta, &quot;../Database/assets/scan akta/&quot;.$sc_akta_kelahiran);
                    
                    $ekstensikk = explode(&quot;.&quot;, $_FILES[&#039;sc_kk&#039;][&#039;name&#039;]);
                    $sc_kk = &quot;kk-&quot;.round(microtime(true)).&quot;.&quot;.end($ekstensikk);
                    $sumberkk = $_FILES[&#039;sc_kk&#039;][&#039;tmp_name&#039;];
                    
                    $uploadkk = move_uploaded_file($sumberkk, &quot;../Database/assets/scan kk/&quot;.$sc_kk);
                    
                    $ekstensiktp = explode(&quot;.&quot;, $_FILES[&#039;sc_ktp&#039;][&#039;name&#039;]);
                    $sc_ktp = &quot;ktp-&quot;.round(microtime(true)).&quot;.&quot;.end($ekstensiktp);
                    $sumberktp = $_FILES[&#039;sc_ktp&#039;][&#039;tmp_name&#039;];
                    
                    $uploadktp = move_uploaded_file($sumberktp, &quot;../Database/assets/scan ktp/&quot;.$sc_ktp);
                    
                    $ekstensisc_perjanjian_krjsm = explode(&quot;.&quot;, $_FILES[&#039;sc_perjanjian_krjsm&#039;][&#039;name&#039;]);
                    $sc_perjanjian_krjsm = &quot;perjanjian kerjasama-&quot;.round(microtime(true)).&quot;.&quot;.end($ekstensisc_perjanjian_krjsm);
                    $sumbersc_perjanjian_krjsm = $_FILES[&#039;sc_perjanjian_krjsm&#039;][&#039;tmp_name&#039;];
                    
                    $uploadperjanjian_krjsm = move_uploaded_file($sumbersc_perjanjian_krjsm, &quot;../Database/assets/scan surat perjanjian kerjasama/&quot;.$sc_perjanjian_krjsm);
                    
                    if( $uploadakta || $uploadkk || $uploadktp || $uploadperjanjian_krjsm) {
                        $tkns2-&gt;tambah($almt, $negara, $kota, $kode_pos, $nib, $no_rek, $sc_akta_kelahiran, $sc_kk, $sc_ktp, $sc_perjanjian_krjsm);
                        //$query = &quot;INSERT INTO tkns2 (id_tkns2, almt, negara, kota, kode_pos, nib, no_rek, sc_akta_kelahiran, sc_kk, sc_ktp, sc_perjanjian_krjsm)  VALUES (&#039;&#039;, &#039;$almt&#039;, &#039;$negara&#039;, &#039;$kota&#039;, &#039;$kode_pos&#039;, &#039;$nib&#039;, &#039;$no_rek&#039;, &#039;$sc_akta_kelahiran&#039;, &#039;$sc_kk&#039;, &#039;$sc_ktp&#039;, &#039;$sc_perjanjian_krjsm&#039;)&quot;;
                        header(&quot;location: ?page=Halaman registrasi teknisi2&quot;);
                        //mysqli_query($conn, $query);
                        
                        //return mysqli_affected_rows($conn); 
                         
                    } else {
                        echo &quot;&lt;script&gt;alert(&#039;Unggah dokumen gagal!&#039;)&lt;/script&gt;&quot;;
                }
            }
        }

public function tambah($almt, $negara, $kota, $kode_pos, $nib, $no_rek, $sc_akta_kelahiran, $sc_kk, $sc_ktp, $sc_perjanjian_krjsm) { $db = $this->mysqli->conn; $db->query("INSERT INTO tkns2 VALUES ('', '$almt', '$negara', '$kota', '$kode_pos', '$nib', '$no_rek', '$sc_akta_kelahiran', '$sc_kk', '$sc_ktp', '$sc_perjanjian_krjsm')") or die ($db->error); }


avatar muhammaddafaassidqi
@muhammaddafaassidqi

2 Kontribusi 0 Poin

Diperbarui 2 bulan yang lalu

1 Jawaban:

Koneksi database gagal Periksa apakah koneksi database berhasil dilakukan dengan memanggil mysqli_connect_error(). Jika ada error, periksa konfigurasi koneksi database. Query insert tidak benar Periksa apakah query insert sudah benar sesuai sintaks SQL. Periksa nama tabel, nama field, tanda kutip, dll. Variabel belum di-escape Gunakan fungsi mysqli_real_escape_string() untuk mengekape variabel sebelum dimasukkan ke query SQL agar terhindar dari SQL injection. Table Lock Jika query insert dipanggil berulang kali secara bersamaan, ada kemungkinan terjadi table lock. Gunakan locking agar proses insert berjalan serialize. Field tidak sesuai Periksa apakah jumlah field dan tipe datanya sudah sesuai dengan definisi tabel di database. Auto increment primary key Jika primary key autoincrement, jangan memasukkan nilai manual, biarkan auto increment bekerja.

avatar adamajalah27
@adamajalah27

119 Kontribusi 39 Poin

Dipost 2 bulan yang lalu

Login untuk ikut Jawaban