CRUD tidak muncul error

tidak muncul error pas di button delete

Viewusers.php

 <?php
	include "class/pengarsipan.php";
	$pengarsipan = new pengarsipan();
?>

<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<ol class="breadcrumb">
		        <li><a href="application.php"><i class="fa fa-tachometer-alt"></i> Dashboard</a></li>
		        <li><a href=""><i class="fa fa-user"></i> Manajemen Users</a></li>
		        <li><i class="fa fa-address-card"></i> Daftar Users</li>
	    	</ol>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="table-responsive">
				<?php
					$no = 1;

				?>

				<table class="table table-bordered table-hover table-striped tablesorter">
					<thead>
						<tr>
							<th width="5%" style="text-align: center;">No</th>
							<th>Nama Lengkap</th>
							<th>Username</th>
							<th>Password</th>
							<th>Hak Akses User</th>
							<th colspan="3" style="text-align: center;">Aksi</th>
						</tr>
					</thead>
					<tbody>
					<?php $result = $pengarsipan->getDataLogin(); ?>
					<?php while ($data = $result->fetch_assoc()) :?>
						<tr>
							<td width="5%" style="text-align: center;"><?php echo $no++; ?></td>
							<td><?php echo $data['nama']; ?></td>
							<td><?php echo $data['username']; ?></td>
							<td><?php echo $data['password']; ?></td>
							<td><?php echo $data['hak']; ?></td>
							<td width="8%"><a href="application.php?page=profileusers&username=<?php echo $data['username'];?>" class="btn btn-success">Detail</a></td>
							<td width="8%"><a href="application.php?page=updateusers&username=<?php
						echo $data['username'];
						?>" class="btn btn-primary">Ubah</a></td>
							<td width="8%"><a href="application.php?page=datausers" class="btn btn-danger" onclick="deleteThis(<?php echo $data['username']; ?>)">Hapus</a></td>
						</tr>
					</tbody>
					<?php endwhile; ?>
				</table>
			</div>
		</div>
	</div>
</div>
					<script>
			            $(document).ready(function() {
			                $('#dataTables-example').DataTable({
			                        responsive: true
			                });
			            });
			        </script>
					<script>
			            function deleteThis(username){
			                if (confirm("Are you sure to delete this data?")) {
			                    $.ajax({
			                        type: 'post',
			                        url: 'controllers/users/delete.php',
			                        data: {username:username},
			                    succes : function(data){
			                        if(data){
			                            alert('data deleted');
			                            window.location="application.php?page=datausers";
			                        } else {
			                            alert ("Can't delete data row" )
			                        }
			                    }
			                    })
			                }
			            }
			        </script>

delete.php

 <?php
	include "/../../class/pengarsipan.php";
	$pengarsipan = new pengarsipan();

	//mengisi atribut dengan js delete
	$pengarsipan->username = $_POST['username'];
	//menampung hasil dari method hapus
	$error = $pengarsipan->delete();
	//pengecekan eror atau berhasil, !$error = berhasil
	if(!$error){
		//memanggil tampilan data
		header("location: ../../application.php?page=datausers");
	} else {
		//membuat session untuk menampilkan pesan error bernama message
		session_start();
		$_SESSION['message'] = $error;
		//memanggil data kembali
		header("location: ../../application.php?page=datausers");
	}
?>

pengarsipan.php

 public function delete(){
			$db = new Database();
			//membuka koneksi
			$dbConnect = $db->connect();
			//querry menghapus data
			$sql = "DELETE FROM login Where username = '{$this->username}'";
			//eksekusi querry diatas
			$data - $dbConnect->query($sql);
			//menampung error query simpan data
			$error = $dbConnect->error;
			//menutup koneksi
			$dbConnect = $db->close();
			//mengembalikan nilai error
			return $error;
		}
avatar bagasnuralim
@bagasnuralim

61 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

3 Jawaban:

coba di die dump bro diquery deletenya di file pengarsipan.php, itu $this->username dapet drmn?

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 6 tahun yang lalu

dari delete.php

avatar bagasnuralim
@bagasnuralim

61 Kontribusi 0 Poin

Dipost 6 tahun yang lalu

Emang bs gan cara kayak gitu? Klo mau dijadiin parameter di method deletenya. Jd kyk gini <pre> $username = $_POST['username']; $error = $pengarsipan-&gt;delete($username); //nah di file pengarsipannya tinggal dioper dah parameternya </pre>

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban