Tuesday, October 19, 2010

Alert Before Delete

Table: hantu
ID name
1 Hantu Raya
2 Hantu Ini
3 Hantu Itu

SQL Data Dari Table hantu:
<?php
$sql=mysql_query("SELECT * FROM hantu");
while($result=mysql_fetch_array($sql){
$nama=$result['name'];
$id=$resul['ID'];
echo $nama."<a href=javascript:; onClick=confirmDel('".$name."','".$id."');>Batal</a>";// display nama hantu serta link untuk padam
}
?>

<head>
<script language="javascript" type="text/javascript">
function confirmDel(name,id){
    if(confirm("Anda pasti untuk padam "+name+" ?")){
        window.location="delete.php?status=padam&name="+name+"&id="+id;
    }
}
</script>// skrip diletakkan pada tag <head>
</head>

delete.php
if($_GET['status']=='padam'){
mysql_query("DELETE FROM hantu WHERE ID='$_GET[id]'");
}

No comments:

Post a Comment