JavaScript Editor Javascript source editor     Web programming 

Team LiB
Previous Section Next Section

Creating the Record Deletion Mechanism

The record deletion mechanism is virtually identical to the script used to view a record. In fact, you can just take the first 44 lines of Listing 19.3 and paste them into a new file, called delentry.php, and make the following changes:

  • In lines 7, 37, and 43, change "view" to "delete"

  • In lines 24 and 39, change "View" to "Delete"

Starting with a new line 45, the remainder of the code for delentry.php is shown in Listing 19.4.

Listing 19.4. Script Called delentry.php for Selecting and Deleting a Record
45:   //check for required fields
46:     if ($_POST[sel_id] == "") {
47:       header("Location: delentry.php");
48:       exit;
49:   }
51:   //issue queries
52:   $del_master = "delete from master_name where id = $_POST[sel_id]";
53:   mysql_query($del_master);
55:   $del_address = "delete from address where id = $_POST[sel_id]";
56:   mysql_query($del_address);
58:   $del_tel = "delete from telephone where id = $_POST[sel_id]";
59:   mysql_query($del_tel);
61:   $del_fax = "delete from fax where id = $_POST[sel_id]";
62:   mysql_query($del_fax);
64:   $del_email = "delete from email where id = $_POST[sel_id]";
65:   mysql_query($del_email);
67:   $del_note = "delete from personal_notes where id = $_POST[sel_id]";
68:   mysql_query($del_master);
70:   $display_block = "<h1>Record(s) Deleted</h1>
71:   <P>Would you like to
72:   <a href=\"$_SERVER[PHP_SELF]\">delete another</a>?</p>";
73: }
74: ?>
75: <HTML>
76: <HEAD>
77: <TITLE>My Records</TITLE>
78: </HEAD>
79: <BODY>
80: <?php echo $display_block; ?>
81: </BODY>
82: </HTML>

Picking up with line 45, the script looks for the required field, $_POST[sel_id], just as it did in the selentry.php script. If that required value does not exist, the user is redirected to the selection form. In lines 5268, queries delete all information related to the selected individual, from all tables. Lines 7072 place a nice message in $display_block, and the script exits and prints the HTML to the screen. An output of the record deletion script is shown in Figure 19.6.

Figure 19.6. Deleting a record.

When you go back to the record selection form after deleting a record, you'll note that the individual you deleted is no longer in the selection menuas it should be!

    Team LiB
    Previous Section Next Section

    JavaScript Editor Javascript source editor     Web programming