public function delete($id = 0) { if ($id != 0) { // Create and delete customer $customer = new customer($id); $customer->delete(); } else { $database = $_SESSION['database']; $id = $database->prepare_input($id); $customer_query = $database->query("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int) $this->id . "'"); // Reset id, otherwise one might think this customer (still) exists in db $this->id = 0; } }
$customerInst = new customer(); ####################################################################### ## perform action $status = 1; if (tool::securePost('action') == "save" && tool::securePost('id')) { # fill customer with submitted data $customerInst->id = tool::securePost('id'); $customerInst->fill(tool::securePostAll()); $status = $customerInst->update(); } elseif (tool::securePost('action') == "save") { $customerInst->fill(tool::securePostAll()); $status = $customerInst->insert(); } if (tool::securePost('action') == "delete") { $customerInst->id = tool::securePost('id'); $customerInst->delete(); } if (tool::securePost('action') == "edit") { $status = 0; $customerInst->activate(tool::securePost('id')); } ####################################################################### ## make edit / new form if (!$status) { echo "<h2>" . $lang['common_editRecord'] . " (<a href=\"" . $toolInst->encodeUrl("index.php?content=" . $content) . "\">" . $lang['common_newRecord'] . "</a>)</h2>\n"; } else { $customerInst->clear(); echo "<h2>" . $lang['common_newRecord'] . "</h2>\n"; } ?>
<?php if ($_POST) { include_once $_SERVER['DOCUMENT_ROOT'] . '/config/database.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '/objects/customer.php'; $database = new database(); $db = $database->getConnection(); $customer = new customer($db); $customer->cust_kode = $_POST['object_id']; if ($customer->delete()) { echo "customer berhasil dihapus."; } else { echo "customer tidak bisa dihapus."; } }