Deleting rows using a primary key value is a minor modification to the update functionality of the script in Example 6-8. For example, the following fragment creates and runs a query to delete a specified customer identified by the value of $custID
:
Deleting MySQL Rows
// Connect to the database, clean, and validate data // We have a custID. Set up a delete query $query = "DELETE FROM customer WHERE cust_id = $custID"; if ( (@ mysql_query ($query, $connection)) && @ mysql_affected_rows( ) == 1) { // Query ran ok // Relocate to the receipt page with status=T header("Location: " . "delete_receipt.php?" . "cust_id=$custID" . "&status=T"); } else { // Failed to delete customer row. // Relocate to the status page with status=F header("Location: " . "delete_receipt.php?" . "status=F"); }
by
updated