Jump to content

Delete Y/N Option


aztec

Recommended Posts

Hello

 

Part of my database management modules includes an option to delete an entire row from the database, this works without any problems.

 

However I would like to include an option that after the DELETE is clicked a YES or No button would be displayed before the actual delete in the MYSQL database took place, to allow second thoughts.

 

i.e. click YES to delete or click NO to cancel the delete operation.

 

I have been searching both the forum and the Web with no success.

 

Any help or guidances much appreciated.

 

Kind Regards

Link to comment
Share on other sites

you can do this with javascript:

something like

 

<script type="text/javascript">
function confirmDelete(){
var answer = confirm("Delete Row?");
if(answer){
alert("Row Deleted!");
window.location = "http://www.yourwebsite.com/delete-row.php";
} else{
alert("Row was not deleted!");
}
}
</script>
<a href="javascript:void(0)" onClick="confirmDelete()">Delete</a>

Link to comment
Share on other sites

Hello

 

Many thanks for your response. Obviously I will try all options but at this time there is no javascript used in the modules therefore I would prefer to use PHP if at all possible.

 

<a href="delete.php" onClick="return confirm('Delete item?');">Delete</a>

 

Is onClick a javascript function.

 

Regards

Link to comment
Share on other sites

Yes, it is.

 

for php you can do something like

 

<form method="post" action="deleterow.php">
<input type="hidden" name="row" value="<?php echo $row['id']; ?>">
<input type="submit" name="submit" value="Yes"><input type="submit" name="submit" value="No">
</form>

 

//deleterow.php

<?php

$submit = $_POST['submit'];

if($submit == 'Yes'){
// delete row
}else {
// do something else
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.