Delete Confirmation Dialog Box

Discussion in 'PHP' started by dynx, Jul 28, 2009.

  1. #1
    Hi there! Its me again... Im wondering whats the simple way for me to setup a Delete Confirmation Box with following codes I have:

    crm_delete.php:

    <html>
    <head></head>
    <body>
    <!-- standard page header -->
    <?php
    // includes
    include('crm_conf.php');

    // check for record ID
    if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
    {
    die('Missing record ID!');
    }

    // open database connection
    $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!');

    // select database
    mysql_select_db($db) or die ('Unable to select database!');

    // generate and execute query
    $id = $_GET['id'];
    $query = "DELETE FROM Cust_tbl WHERE custID = '$id'";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

    // close database connection
    mysql_close($connection);

    // print result
    echo '<font size=-1>Deletion successful.';
    echo '<a href=index.php>Go back to the main menu</a>.</font>';
    ?>
    <!-- standard page footer -->
    </body>
    </html>

    Index.php

    <html>
    <head></head>
    <body>

    <!-- standard page header -->

    <?php
    // includes
    include('crm_conf.php');


    // open database connection
    $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!');

    // select database
    mysql_select_db($db) or die ('Unable to select database!');

    // generate and execute query
    $query = "SELECT * FROM Cust_tbl ORDER BY custName";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

    // if records present
    if (mysql_num_rows($result) > 0)
    {

    // iterate through resultset
    // print title with links to edit and delete scripts
    while($row = mysql_fetch_object($result))
    {
    ?>
    <font size="-1"><b><?php echo $row->custID; ?></b>[<?php echo $row->custName; ?>]</font>
    <br>
    <font size="-2"><a href="crm_edit1.php?id=<?php echo $row->custID; ?>">
    edit</a> | <a href="crm_delete.php?id=<?php echo $row->custID; ?>">
    delete</a></font>
    <p>

    <?php
    }
    }
    // if no records present
    // display message
    else
    {
    ?>
    <font size="-1">No releases currently available</font><p>
    <?php
    }

    // close connection
    mysql_close($connection);
    ?>
    <font size="-2"><a href="crm_add.php">Add New</a></font>
    <!-- standard page footer -->
    </body>
    </html>

    Awaiting to all your reply... TIA
     
    dynx, Jul 28, 2009 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    Add javascript in head tag
    
    <script language="JavaScript">
    function conf(){
    	var sure = confirm("Are you sure you want to delete this record ?");
    	if(! sure)
    	        return false;
    	else
    		return true;
    }
    </script>
    
    HTML:
    Change delete link
    <a href="crm_delete.php?id=<?php echo $row->custID; ?>">
    delete</a>

    with this

    <a href="crm_delete.php?id=<?php echo $row->custID; ?>" onClick="return conf();">
    delete</a>
     
    greatlogix, Jul 28, 2009 IP