A very simple script to do deletion with PHP and a prompt confirmation using javascript.
Of course, you can have a server side confirmation using PHP as well.
I have a list of records in a table, and each row there is a Delete link. Upon clicking on the link, user will be prompted to confirm the deletion.
<a href=”list-tenants.php?del=1&tenant_id=<?php echo $tenant["tenant_id"]; ?>” onClick=”return confirmdelete();”>Delete</a>
On the javascript, put in this code :
<script type=”text/javascript”>
function confirmdelete() {
return confirm(’Are you sure you want to delete this record?’);
}
</script>
If user clicks ok, in the page we use PHP to check the GET variable being passed over.
<?php
if($_GET["del"]==1) {
$tenantid=$_GET["tenant_id"];
$delete_sql = “DELETE from tenant WHERE tenant_id=$tenantid”;
$delete = mysql_query($delete_sql) or die(mysql_error());
}
?>



Home