Dear Sir,

I have following codes

if(isset($_POST['delete']))
    {
        // 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);

if(!$result){
echo "<script>alert('Record not deleted')</script>";
}else{
echo ("<script>alert('Record deleted successfully')</script>"); 
}
}

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

[IMG]http://i42.tinypic.com/15mzc6g.jpg[/IMG]

Please help

I would suggest that you show the popup message prior to the post. You can achieve this result using javascript and/or jquery. It can be as simple as using the confim method on your button... onclick="return confirm('Are you sure you want to delete the record?');

Thanks sir, but we should add your codes in my code?
Please modify my codes if possible.

Your code is not complete. I assume that you have a form somewhere that is handing the submission process? If you have a submit button that is there for the user to initiate the deletion process, then...

<form action="deleteRecord.php" >

<input name="deleteBtn" type="submit" value="Delete" 
       onclick="return confirm('Are you sure you want to delete the record?')"/>

</form>

Thanks for helping, now I have following modified codes

<?php
    require_once("connect.php");

    // DELETE
    if(isset($_POST['delete']))
    {
        // 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>";
            }else{
            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);"
>

        </div>
      </form>

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.

if(isset($_POST['delete']))   

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

Please help again. Thanks

Hai;

Try this

<script src="http://code.jquery.com/jquery-1.8.1.js"></script>
<?php
    //require_once("connect.php");

    // DELETE
    if(isset($_POST['delete']))
    {
        echo '<h1>Posted Value ='.$_POST['delete'].'</h1>';

     }
?>

      <form name="form1" id="formId" action="" method="post">
       <input name="delete" type="hidden" value="Deleted"  />
        <table border=0; cellpadding="1" cellspacing="1" bgcolor="" align="center" >

        <div style=text-align:center;margin-top:20px;>

      <input type="button" name="delete" value="Delete" onclick="formConfirm()">

        </div>
        </table>
      </form>
<script type="text/javascript">

    function formConfirm() {
        if(!confirm("Do you really want to delete this record?")) return false;
        $("#formId").submit();
    }

</script>

Dear Sir, can please provide some more explation about following funciont?

 function formConfirm() {
        if(!confirm("Do you really want to delete this record?")) return false;
        $("#formId").submit();
    }
onclick="return confirm('Are you sure you want to delete the record?');"

I use this in my projects.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.