I want to delete project from database.Before deleting I want to confirm it whether user want to delete or not.If user click on okay it has to call delete function.But in the code when user click the function is get called not only user click on okay but also click on concel.For other alter statement it is working fine.For calling php function only it gives problem.
How can I solve this?
code is,
<a href="http://localhost/Performance/project/ShowAllProjects.php?project_id='.$row['project_id'].'"><img src="http://localhost/performance/css/delete.png" title="delete" alt="running test" style="width:15px;height:15px;border:0;margin-left:1cm" Onclick="deleteProject();"/></a>
<script>
function deleteProject() {
var r = confirm("Press a button!");
if (r == true) {
//alert("You pressed OK!");
alert("<?php confirmDelete(); ?>");
} else {
alert("You pressed Cancel!");
}
}
</script>
<?php
function confirmDelete(){
$sql="DELETE FROM project_table WHERE project_id='".$_GET['project_id']."' AND member_id='".$_SESSION['user_id']."';";
if(mysqli_query($GLOBALS['db'], $sql)) {
echo "Your test deleted successfully";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($GLOBALS['db']);
}
}
?>
console.log()instead ofalert()