Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to php and javascript.In my project I can click the delete button.before deleting the record show the alert message and if i click ok record will be delete.But In
My case Alert message is showing in javascript fine.But once alert message shown if click cancel button also record will be deleting.How to solve this problem please help me on this.Thanks in Advance.

What I have tried:

JavaScript
 function ConfirmDelete()
{
  var x = confirm("Are you sure you want to delete?");
  if (x==true)
  {
      return true;
  }
  else
    return false;
}


PHP
if(isset($_POST['Delete']))
		{
	            $sql="UPDATE `organization`
			    SET bbnk_delstatus='Y'
				WHERE bbnk_Id='$select_id'";
			if(mysqli_query($conn,$sql))
			{
				$status= "Record Deleted successfully";
			}
			else
			{
				$status= "connection failed".mysqli_error($conn);
			
			}
				
		}
Posted
Updated 29-Jun-17 7:54am
v3

Unfortunately, you've not shown any sort of connection between your ConfirmDelete() function and your delete statement. First, you should never get to the statement if you do not select 'YES'.

So I'll guess: you're running the ConfirmDelete() function but your actual delete is occurring with ever checking it. You need to rearrange your logic in that function so that the deletion is called if YES is selected, or else it's not called at all.

There's no connection (magical or otherwise) between confirm() unless you make one!
 
Share this answer
 
Comments
Member 13153537 29-Jun-17 13:33pm    
How to do that please any help.Thanks in Advance.
W Balboos, GHB 29-Jun-17 13:48pm    
Check Here: https://www.w3schools.com/jsref/met_win_confirm.asp

Look where the example says: txt = "You pressed OK!";
You would replace that with whatever code you use to access your database. If you do that you should only run that code if YES is clicked.
Looks like you need to learn and practice programming.
Advice: follow tutorials and practice.
Your code is overcomplicated
JavaScript
function ConfirmDelete()
{
  var x = confirm("Are you sure you want to delete?");
  if (x==true)
  {
    return true;
  }
  else
    return false;
}

can be simplified to
JavaScript
function ConfirmDelete()
{
  var x = confirm("Are you sure you want to delete?");
  return x;
}

and even to
JavaScript
function ConfirmDelete()
{
  return confirm("Are you sure you want to delete?");
}
 
Share this answer
 
Comments
Member 13153537 30-Jun-17 0:38am    
Thanks for your Advice.I will do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900