Tidak bisa menghapus data dalam script php dengan metode $_GET

Dear Teman-Teman,

Mohon pencerahannya untuk problem pada script php saya, saya tidak bisa menghapus data berdasarkan kriteria id user. metode yang digunakan adalah metode $_GET.

berikut script nya :

Script menampilkan data (daftarguru.php) :

 <?php require_once 'header.php'; require_once 'aside.php';?>
	<main>
		<h4>Home / Daftar Guru</h4>
		<hr/>
		<br/><br/>

		<div>
			<li class="tombol"><a href="tambahguru.php">Tambah</a></li>
		</div>

		<br>

			<?php
				$link = mysqli_connect('localhost','root','','db_sekolahkoding');



				$perpage	= 5;
				$page 		= isset($_GET['halaman']) ? (int)$_GET['halaman'] : 1;
				$start		= ($page > 1) ? ($page * $perpage) - $perpage :0;

				$result 	= mysqli_query ($link, "SELECT * FROM tblguru");
				$total		= mysqli_num_rows($result);

				$pages		= ceil($total/$perpage);

				$articles	= "SELECT * FROM tblguru ORDER BY No DESC LIMIT $start, $perpage";
				$tampil		= mysqli_query($link,$articles);

				$no 		= $start + 1;

				echo "
					<table>
					<caption style=\"text-align:center;\"><h4>DAFTAR BIODATA GURU<h4></caption>
					<tr>
						<th>No</th>
						<th>NIP</th>
						<th>Nama</th>
						<th>Bidang Studi</th>
						<th>No. Handphone</th>
						<th>Alamat</th>
						<th>Aksi</th>
					</tr>";

				while ($data = mysqli_fetch_assoc($tampil)) {

				echo "
					<tr>
						<td>$no</td>
						<td>$data[Nip]</td>
					    <td>$data[Nama]</td>
						<td>$data[Bidangstudi]</td>
						<td>$data[Nohandphoneguru]</td>
						<td>$data[Alamat]</td>
						<td>
						<a href=\"editguru.php?edit=$data[No]\">Edit</a> |
						<a href=\"hapusguru.php?hapus=$data[No]\">Hapus</a>
						</td>
					</tr>";
				    $no++;

				    }
				    echo "</table>";

				    	echo "<br>";
   					    echo "<b>Halaman : </b>";
				    	for ($i=1; $i<=$pages; $i++){
				    	echo "<div class=\"pagination\">";
						echo "<tr><a class=\"paginationlink\" href=\"?halaman=$i\">$i</a></tr>";
						echo "</div>";
				}

				mysqli_close($link);
			?>

	</main>
<?php require_once 'footer.php'; ?>


-------------------------------------------------------------

Script menghapus data (hapusguru.php) :

 <?php require_once 'header.php'; require_once 'aside.php';?>
<main>
		<h4>Home / Daftar Guru</h4>
		<hr/>
		<br/><br/>

		<?php

		$link	= mysqli_connect('localhost', 'root', '', 'db_sekolahkoding');
		$id		= @$_GET['No'];

					$hapus	= "DELETE FROM tblguru WHERE No='$id'";

							if (mysqli_query ($link, $hapus)) {
								echo "<script language=\"javascript\">
							         alert (\"Data berhasil dihapus\")
							         document.location=\"daftarguru.php\";
							         </script>";

							}else{
								echo "<script language=\"javascript\">
							         alert (\"Gagal hapus data\")
							         document.location=\"daftarguru.php\";
							         </script>";
			 					  }

		    mysqli_close($link);
		?>
</main>
<?php require_once 'footer.php'; ?>

avatar permadiopa
@permadiopa

17 Kontribusi 1 Poin

Diperbarui 6 tahun yang lalu

3 Jawaban:

kenapa disini get nya namanya hapus

 <a href=\"hapusguru.php?hapus=$data[No]\">Hapus</a>

tapi kok pas di panggil namanya NO ???

 $id		= @$_GET['No'];

harusnya

 $id		= $_GET['hapus'];

#cmiiw

avatar Nandar
@Nandar

648 Kontribusi 204 Poin

Dipost 6 tahun yang lalu

@Nandar,

Betul gan, saya kira untuk script :

 $id = @$_GET['No'];

artinya $id adalah variable untuk mengambil data dari kolom "No" pada "tblguru" di database mysql nya yang akan dihapus.

karena sesuai perintah dari method post di script halaman daftarguru.php :

<a href=\"hapusguru.php?hapus=$data[No]\">Hapus</a>

tapi, setelah saya menerapkan saran dari agan @Nandar, akhirnya terpecahkan juga problemnya. terimakasih atas pencerahannya, mohon dimaklu saya masih pemula dan masih belajar. :D

avatar permadiopa
@permadiopa

17 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

yap sama-sama

avatar Nandar
@Nandar

648 Kontribusi 204 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban