Daftar dan Belajar Sekarang!

Error pada pertambahan php ke database(tolong bantu t_t)

foto Azni863
1 Kontribusi 0 Coto
1 bulan yang lalu
ane udah perika berkali kali tapi tetep kaya gini gadikasih tau salahnya dimana pas mau nambah data tuhhttps://i.imgur.com/bReEy3n.png
<?php

include_once("koneksi.php");


$result = mysqli_query($connect, "SELECT * FROM perizinan ORDER BY no DESC");
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="widht=device.width, initial-scale=1">
	<title>Perizinan BAKNUS 666</title>
	<link rel="stylesheet" type="text/css" href="sta.css">
</head>
<body>
	<?php session_start(); ?>
	<header>
		<div class="container">
			<nav>
				<img src="logoBN.PNG" height="90%" width="15%">
				<h4 class="AZAFRI"><a href="index.html">PENDATAAN Surat Perizinan Keluar<br><span>SMK BAKTI NUSANTARA 666<br></a></h4>
				<ul>
					<li><a href="index.php">Home</a></li>
					<li><a href="o.php">Jadwal Matpel</a></li>
					<li><a href="a.php">Tambah Data</a></li>
					<li><a href="logout.php">Logout</a></li>
				</ul>
				</ul>
			</nav>
		</div>
	</header>
		<div class="content">
			<div class="main">
				<?php
				include "koneksi.php";
				?>
				<div class="login-box">
					<br/><br/>
					<h1>Tambah Data Izin</h1>

    <form action="addproses.php" method="post" name="form1">
        <table width="100%" border="0">
          
            <tr>
                <td>No Surat</td>
                <td><input type="text" name="no"></td>
            </tr>
            <tr> 
                <td>NIS</td>  
                     <?php   
                          $con = mysqli_connect("localhost","root","","pkk");  
                      ?>  
                     <td><select name="nis" id="nis" class="form-control" onchange='changeValue(this.value)' required >  
                          <?php   
                          $query = mysqli_query($con, "select * from siswa order by nis asc");  
                          $result = mysqli_query($con, "select * from siswa");  
                          $a          = "var nama = new Array();\n;";  
                          $b          = "var kelas = new Array();\n;";  
                          while ($row = mysqli_fetch_array($result)) {  
                               echo '<option name="nis" value="'.$row['nis'] . '">' . $row['nis'] . '</option>';   
                          $a .= "nama['" . $row['nis'] . "'] = {nama:'" . addslashes($row['nama'])."'};\n";  
                          $b .= "kelas['" . $row['nis'] . "'] = {kelas:'" . addslashes($row['kelas'])."'};\n";  
                          }  
                          ?>  
                     </select></td>  
                </tr>  
                <tr>  
                     <td>Nama </td>  
                     <td><input type="text" name="nama" id="nama" readonly></td>  
                </tr>  
                <tr>  
                     <td>Kelas</td>  
                     <td><input type="text" name="kelas" id="kelas" readonly></td>  
                </tr>  
           
            <tr> 
                <td>Tanggal</td>
                <td><input type="date" name="tanggal"></td>
            </tr>
            <tr> 
                <td>Keterangan</td>
                <td><input type="text" name="keterangan"></td>
            </tr>
            <tr> 
                <td>Pelajaran Yang Ditinggalkan</td>
                <td><input type="text" name="pelajaran_ditinggalkan"></td>
            </tr>
           
            <tr> 
                <td></td>
                <td><input type="submit" name="Submit" value="Tambah"></td>
            </tr>
        </table>
    </form>
						</tbody>

			
				<br/>
				<br/>
				
			</div>
			</div>
		</div>
		<div class="footer">
			<marquee><p>Copyright@2020 SMK_BAKTI_NUSANTARA_666 ALL RESERVED</p></marquee>
		</div>
	</div>
</body>
</html>
 <script type="text/javascript">   
                          <?php   
                          echo $a;   
                          echo $b; ?>  
                          function changeValue(id){  
                            document.getElementById('nama').value = nama[id].nama;  
                            document.getElementById('kelas').value = kelas[id].kelas;  
                          };  
                          </script>
ini kodingan tampilan tambah
<?php
if(isset($_POST['Submit'])){
   
}

        $no = $_POST['no'];
        $nis = $_POST['nis'];
        $nama = $_POST['nama'];
        $kelas = $_POST['kelas'];
        $tanggal = $_POST['tanggal'];
        $keterangan = $_POST['keterangan'];
        $pelajaran_ditinggalkan = $_POST['pelajaran_ditinggalkan'];

    include('koneksi.php');    
        $result = mysqli_query($connect,"INSERT INTO perizinan(no,nis,nama,kelas,tanggal,keterangan,pelajaran_ditinggalkan) VALUES(null,'$nis','$nama','$kelas','$tanggal','$keterangan','$pelajaran_ditinggalkan')");
        if(mysqli_affected_rows($connect) > 0){
        echo "<script>alert('Berhasil Menambah Data');
                document.location.href='index.php';
                </script>";
      
        }
    ?>
ini kodingan php buat tambahnya
<?php

include_once("koneksi.php");


$result = mysqli_query($connect, "SELECT * FROM perizinan ORDER BY no DESC");
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="widht=device.width, initial-scale=1">
	<title>Perizinan BAKNUS 666</title>
	<link rel="stylesheet" type="text/css" href="sta.css">
</head>
<body>
	<?php session_start(); ?>
	<header>
		<div class="container">
			<nav>
				<img src="logoBN.PNG" height="90%" width="15%">
				<h4 class="AZAFRI"><a href="index.html">PENDATAAN Surat Perizinan Keluar<br><span>SMK BAKTI NUSANTARA 666<br></a></h4>
				<ul>
					<li><a href="index.php">Home</a></li>
					<li><a href="o.php">Jadwal Matpel</a></li>
					<li><a href="a.php">Tambah Data</a></li>
					<li><a href="logout.php">Logout</a></li>
				</ul>
				</ul>
			</nav>
		</div>
	</header>
		<div class="content">
			<div class="main">
				<?php
				include "koneksi.php";
				?>
				<h1 align="center">Data Murid Izin Keluar</h1><br><br>
					<table border="1" width="100%" align="center">
						
						<thead>
							<tr>
							<th>No Surat</th>
							<th>NIS</th>
							<th>Nama Siswa</th>
							<th>Kelas</th>
							<th>Tanggal Izin</th>
							<th>Keterangan</th>
							<th>Pelajaran Yang Ditinggalkan</th>
							<th>Update</th>
							</tr>
						</thead>

						<tbody>

							<?php
							$ambildata=mysqli_query($connect, "SELECT * FROM perizinan order by no asc");
							while ($perizinan=mysqli_fetch_array($ambildata)) {
							?>
								<tr>
									<td><?php echo $perizinan['no'];?></td>
									<td><?php echo $perizinan['nis'];?></td>
									<td><?php echo $perizinan['nama'];?></td>
									<td><?php echo $perizinan['kelas'];?></td>
									<td><?php echo $perizinan['tanggal'];?></td>
									<td><?php echo $perizinan['keterangan'];?></td>
									<td><?php echo $perizinan['pelajaran_ditinggalkan'];?></td>
									<?php echo "<td><center><a href='edit.php?no=$perizinan[no]'>Edit</a><center></td></tr>";?>
								</tr>
							<?php
							}
							?>
						</tbody>

					</table>
				<br/>
				<br/>
				
			</div>
			
		</div>
		<div class="footer">
			<marquee><p>Copyright@2020 SMK_BAKTI_NUSANTARA_666 ALL RESERVED</p></marquee>
		</div>
	</div>
</body>
</html>
ini tampilan index/tampilan utamanya tolong bantuannya ya gan soalnya tugas sekolah

Jawaban
foto bosque
177 Kontribusi 99 Coto
1 bulan yang lalu
Hai @Azni863 kamu ubah dibagian tambah data. Seperti ini
<?php
include_once('koneksi.php'); //biar aman mencegah koneksi double
if(isset($_POST['Submit'])){
   $no = $_POST['no'];
        $nis = $_POST['nis'];
        $nama = $_POST['nama'];
        $kelas = $_POST['kelas'];
        $tanggal = $_POST['tanggal'];
        $keterangan = $_POST['keterangan'];
        $pelajaran_ditinggalkan = $_POST['pelajaran_ditinggalkan'];

        
        $result = mysqli_query($connect,"INSERT INTO perizinan(no,nis,nama,kelas,tanggal,keterangan,pelajaran_ditinggalkan) VALUES(null,'$nis','$nama','$kelas','$tanggal','$keterangan','$pelajaran_ditinggalkan')");
if($result) {
header("Location: index.php");
}else{
echo "gagal memasukkan data";
}

        
    ?>
semoga membantu ^^
  • Masih tetep putih gan, yg musingin tuh gadikasih taunya errornya bagian mana - Azni863
  • Udah sy edit jawabannya, jika msh gagal coba di die dump querynya - bosque


Login untuk diksusi di forum sekolah koding