You are trying to alert the user whether to continue or not. Here is that code
if (confirm('Are you sure you want to do this thing into the database?')) {
// operation to execute
} else {
// operation on false
}
call the function by onclick event in edit e.g(onclick="showUser(this.value)"
)
AJAX:
<script>
function showUser(str) {
if (confirm('Are you sure you want to do this thing into the database?')) {
// operation to execute
if (str == "") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
}
xmlhttp.open("GET","linktophp.php?q="+str,true);
xmlhttp.send();
} else {
alert("cancelled");
}
}
</script>
PHP FILE:
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','****','abc123','my_db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="DELETE FROM user WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
?>