Pages

Sabtu, 03 Mei 2014

Script Koneksi.php


<?php
$host="localhost"; // nama host
$username="root"; // nama user
$password="12345678"; // password host
$db="artikel"; // nama database yang dibuat
$query=mysql_connect($host,$username,$password) or die ("koneksi gagal");
mysql_select_db($db,$query);
?>
2. Hapus.php

<?php
include ('koneksi.php');
$id=$_GET['id'];
$query_string="select * from artikel"; // mendiskripsikan bahwa mengambil dari database "artikel"
$query=mysql_query($query_string);
while($record=mysql_fetch_array($query))
{ ?><table width="500" border="0">
<tr>
<td width="100"><?php echo " $record[nama] "; ?> </td>
<td width="100"><?php echo " $record[nama] "; ?> </td>
<td width="100"> <?php echo " $record[nama] "; ?> </td>
<td width="100">
<?php $id=$_GET['id'];// mendiskripsikan alamat setelah tombol submit ter-klik
echo "<form action=hapus2.php?id=$record[id] method=post name=form1 target=_self>"; ?>
<label>
<input type="submit" name="Submit" value="Submit">
</label></td>
</tr>
</table>
</form>

<?php } ?>
3. Hapus2.php

<?php
include ('koneksi.php');
if ($_POST['Submit'])
{
 
$id=$_GET['id'];
mysql_query("delete from artikel where id=$id");
}
 
?>
<script language="javascript"> alert("data anda telah terhapus");
document.location='<?php echo ("index.php"); ?>';</script>

Setelah itu kita panggil menggunakan localhost script hapus.maka akan menjadi seperti gambar berikut:
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMteY-Hbh7_tmoSdcVkuGvcm1J-x4yCoJs1713mopzqngbzfb9rc_ELGk0vIIXbAA7Bl5DG53Ca_Rm8nEep_6ZMx942HPFMqB6SW4LuAoBppojjdlDbOFAUCWn31gkAyujGqVWXeokG2M/s320/hapus+copy.jpg 



Setelah anda meng clik submit maka akan muncul tampilan sebagai berikut dan data anda sukses terhapus dari database:
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZRoPaLmnDKhXS2sI2gn50LFWhQkyOedQGBCHOITld01OySEJG0S38EKKYudw1OlZZs1X_fAlxYr_MNvdybGFIOcSz45Iy0Z3bGesCCSm6uMsPeC41XXWltX-ancwsWkytDNEwRFjxGoY/s320/submit.jpg 


Tidak ada komentar:

Posting Komentar