input otomatis menggunakan javascript tetapi nama ataupun id tidak bisa tersimpan

function javascript
<?php include "koneksi.php"; ?>
<script type="text/javascript">
		$(document).ready(function(){
			setInterval(function(){
				$("#norfid").load('./form/no_kartu.php')
			}, 5000);  //pembacaan file nokartu.php, tiap 1 detik = 1000
		});
	</script>
tabelΒ 
<table border="1" width="100%" cellpadding="4" cellspacing="0">
	<form method="POST" action="" enctype="multipart/form-data" class="container-fluid">
		<tr>
			<td>No. Kartu</td>
			<td ><div id="norfid"></div></td>
		</tr>
no_kartu.php
<?php
	include "../koneksi.php";
	//baca isi tabel tmprfid
	$sql = mysqli_query($konek, "select * from tmp_rfid");
	$data = mysqli_fetch_array($sql);
	//baca nokartu
	$nokartu = $data['nokartu'];
?>
<div class="form-group">
	<input type="text" name="nokartu" id="nokartu" placeholder="tempelkan kartu rfid Anda" class="form-control" style="width: 200px" value="<?php echo $nokartu; ?>">
</div>
no kartu pada saat tombol simpan diklik, tidak dapat tersimpan
include "koneksi.php";
if (isset($_POST['simpan'])) {
	$nokartu = $_POST['nokartu'];
	$no_nim = $_POST['no_nim'];
	$nama_mhs = $_POST['nama_mhs'];
	$jenis_kelamin = $_POST['jenis_kelamin'];
	$kd_kelas = $_POST['kd_kelas'];
	$kd_jurusan = $_POST['kd_jurusan'];
	$username = $_POST['username'];
	$password = $_POST['password'];
	$folder 	= "./foto_mahasiswa/";
	$foto   	= $_FILES['foto']['name'];
	$tmp_foto   = $_FILES['foto']['tmp_name'];

	$simpan = mysqli_query($konek,"INSERT INTO tbl_mahasiswa('', nokartu, no_nim, nama_mhs, jenis_kelamin, kd_kelas, kd_jurusan, username, password, foto, '') VALUES (
	'',
	'$nokartu',
	'$no_nim',
	'$nama_mhs',
	'$jenis_kelamin',
	'$kd_kelas',
	'$kd_jurusan',
	'$username',
	'$password',
	'$foto',
	'Y')
	");
	if($simpan)
			{
				echo "
					<script>
						alert('Tersimpan');
						window.location.href='./media.php?page=mahasiswa'
					</script>
				";
			}
			else
			{
				echo "
					<script>
						alert('Gagal Tersimpan');
						window.location.href='./media.php?page=mahasiswa'
					</script>
				";
			}
	move_uploaded_file($tmp_foto, $folder . $_POST['no_nim'] . ".jpg");	// Upload Foto
	echo "<script>window.location.href='./media.php?page=mahasiswa'</script>";
}
avatar iqbalaliudin

@iqbalaliudin

2 Kontribusi 0 Poin

  • sebentar,,, aku kurang paham (lebih ke malas membaca ^^) ini maksudnya, save setiap interfal tertentu, atau save saat klik tombol submit ? ? - @mitsuky06
  • saat klik tombol submit, nokartu gak bisa ke save - @iqbalaliudin


Jawaban

nokartu tidak dapat terbaca saat disimpan
avatar iqbalaliudin

@iqbalaliudin

2 Kontribusi 0 Poin


aku kasi reverensi berbeda aja yaa,,, ini yang biasa aku lakuin kalo pake script
<script type="text/javascript">
$("#button_simpan").click(function() {
    var id = $('#id').val();
    var input = $('#input').val();

    if (input.length == 0) { $("#input").focus(); return false; }

    $.ajax({
        type: "POST",
        url: "simpan_data.php",
        data: "id=" + id +
            "&input=" + input,

        success: function(data) {
            $("#tabel_tampil").load('tabel_tampil.php');
        }
    });
});
</script>
<div id="tabel_tampil" name="tabel_tampil">
    <?php
        include tabel_tampil.php; //isi tabel tampil intinya read data database
   ?>
</div>
<input type="hidden" name="id" id="id" value="$x">
<input type="text" name="input" id="input">
<button type="button" id="button_simpan">simpan</button>

dan simpan nya ya simpan sql biasa

<?php 
include "koneksi.php";

$id       = $_POST['id'];
$input    = $_POST['input'];

  $input = "INSERT INTO $table (
  id,
  input)
        VALUES(
        '$id',
        '$input')";
  mysqli_query($koneksi,$input);
}
?>
semoga membantu ^^ ,, maaf kalo beda banget dengan yang di mau
avatar mitsuky06

@mitsuky06

93 Kontribusi 44 Poin


Login untuk gabung berdiskusi