Confirm before delete

Dear Sir,

I have following codes

// Get values from form
$sno = $_POST[‘txtsno’];
$pro = $_POST[‘txtpro’];
$wet = $_POST[‘txtwet’];

$query = “delete from test WHERE sno={$sno}” ;
$result = mysqli_query($con, $query);

echo “”;
echo (“”);

It works fine, but I want to need a confirmation box like this before deleting record

Please help

On the onclick of your submit button put this…

[php]onclick=“return (window.confirm(‘Do you really want to delete this record?’) ? 1 : 0);”[/php]

Thanks for helping, now I have following modified codes


	// Get values from form 
	$sno = $_POST['txtsno'];
	$pro = $_POST['txtpro'];
	$wet = $_POST['txtwet'];

		//$query = "delete from test WHERE sno='".$sno."'" ;
		$query = "delete from ghee WHERE sno={$sno}" ;
		$result = mysqli_query($con, $query);
		if(!$result)			{
		echo "<script>alert('Record not deleted')</script>";
		echo ("<script>alert('Record deleted successfully')</script>"); 


  <form name="form1" action="" method="post">
    <table border=0; cellpadding="1" cellspacing="1" bgcolor="" align="center" >
    <div style=text-align:center;margin-top:20px;>
	  <input type="submit" name="delete" value="Delete" onclick="return (window.confirm('Do you really want to delete this record?') ? 1 : 0);"


When I press delete button then confirmation apperas but…
In both cases (Yes or No), record is deleted automaticlly.

I think when Delete button is pressed then this part of codes runs immediately without caring Yes or No option.


The record must not be deleted in case NO button is pressed.

Please help again. Thanks

What suppose to happen is that it becomes

Return True or Return False.

and return false will cancel the form submission.

You can try this.

1= true
0 = false

[php]onclick=“return (window.confirm(‘Do you really want to delete this record?’) ? true : false);”[/php]

Thank you very much sir,
Now it works fine.
I rate you.

Awesome, that’s for confirming it works.

A lot people don’t say thanks and leave us wondering if we actually helped!

Sir I have already say you THANKS,
Please see post at top of your post.

Sponsor our Newsletter | Privacy Policy | Terms of Service