Jump to content

confirm deletion before deleting


ramiwahdan

Recommended Posts

Hi,

i have delete link for records and it goes to other page to delete all related records in tables. is there away to get confirmation before the delete process starts?

<?Php

include('session.php');
include('dbcon.php');

	if(isset($_GET['Del']))
	{
		
		$userid = $_GET['Del'];
		
		$query = "delete from staff where OracleID='".$userid."'";
		$result = mysqli_query($con,$query);
		
		if($result)
		{
			
			echo "staff deleted";
			
		}
		
		else
		{
			
			echo 'check the errors!';
			
		}
		
		$query2 = "delete from attendance_records where OracleID='".$userid."'";
		$result2 = mysqli_query($con,$query2);
		
		if($result2)
		{
			
          	echo "records deleted";
			
		}
		
		else
		{
			
			echo 'check the errors!';
			
		}
      
      
     header("location:viewstaff.php");
		
		
	}
	else
	{
		
		header("location:viewstaff.php");
		
	}

?>

how to add confirm message with php before deletion is processed?

Link to comment
Share on other sites

On your submit button do this

<input type='submit' name='btn' value='Submit' onclick='return confirmDelete()'>

Then in your script section create this function:

function confirmDelete()
{
	if (!confirm('Are you sure you want to do this delete?'))
		return false;
	else
		return confirm('Are you REALLY sure?');
}

 

Link to comment
Share on other sites

thanks for the help. your function will return Boolean of true or false. After i get the answer how to delete the records?

before i had:

<td><a href="deletestaff.php?GetID=<?php echo $userid?>">Delete</a></td>

with your code i have:

<td><button class="btn btn-primary" name="delete" onclick="return confirmDelete()">Delete</button></td>

so after the function confirms yes for both, how to pass the link

href="deletestaff.php?GetID=<?php echo $userid?>"

thanks

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.