What I want to do is to use a confirm box where if the user clicks OK, to delete a row from my SQL database. I have a js function I use to send the value "delete" to a php function on the same file like this:
<script>
function myFunction() {
if (confirm("Are you sure you want to delete?") == true) {
document.getElementById("delete").name = "delete";
}else{
return false;
}
}
</script>
The button where the user will click to delete an image is this:
<button onclick="myFunction()">Delete Image</button>
I send the value to the PHP function like this:
<input type="hidden" name="" value="delete" id="delete">
This is my PHP function:
if(isset($_POST['delete'])){
$img_path=$_POST['ipath'];
$imgid=$_POST['imgid'];
$link = mysqli_connect($host, $username, $password, $db);
$delete = "DELETE FROM images_info
WHERE Image_Id = $imgid";
$result3 = mysqli_query($link, $delete);
echo "Image Deleted : $imgid";
mysqli_close($link);
}
What am I doing wrong? I believe it's gotta do with the javascript
ajaxfor this.<form action="newsearch.php" method="post">. However I opened and closed several<div>s inside this form. Will this make a difference? @DivyeshSavaliya