A file named del_one_emp.php uses the employee number to look up more data (last and first names) on the employee, which will be used to confirm the deletion. Confirmation is accomplished by pushing a button denoting what name to delete. The button is a submit button with the employee number as its value. When del_emp.php executes, it will delete that record from the table.
<?php // Connect to the database and get the data of interest $db = odbc_connect("iaidb", "css_test", "password") or die ("could not connect<br />"); $id = $_GET["id"]; $stmt = "Select LastName, FirstName from tblEmployees where employeenumber=$id"; $result = odbc_exec($db, $stmt); if ($result == FALSE) die ("could not execute statement $stmt<br />"); $ln = odbc_result($result, "lastname"); $fn = odbc_result($result, "firstname"); ?> <form method="post" action="del_emp.php"> <button type="submit" name="id" value="<?php echo $id;?>"> Delete <?php echo "$ln, $fn";?>? </button> </form> <a href="javascript: history.back()">Back</a>
Deleting the employee information uses del_emp.php to process the input and delete the employee information from the table:
<?php $db = odbc_connect("iaidb", "css_test", "password") or die ("could not connect<br />"); $id = $_POST["id"]; $del_stmt = "delete from tblEmployees where EmployeeNumber=$id"; $result = odbc_exec($db, $del_stmt); if ($result == FALSE) die("<br />Could not execute statement ".$del_stmt); odbc_free_result($result); odbc_close($db); include 'showEditableEmps.php'; ?>