array_push($errors, "[x] Deskripsi tidak boleh kosong"); } if (preg_match("/^[ a-zA-Z0-9\\.,_]*\$/", $instansi) == false) { array_push($errors, "[x] Karakter tidak diperbolehkan"); } if (preg_match("/^[ a-zA-Z0-9\\.,_]*\$/", $deskripsi) == false) { array_push($errors, "[x] Karakter tidak diperbolehkan"); } if (count($errors) > 0) { foreach ($errors as $value) { echo $value . "<br>"; } exit; } $instansiObj->instansi = $instansi; $instansiObj->deskripsi = $deskripsi; $instansiObj->find = $id; $instansiObj->update(); header('location:?page=instansi'); break; case 'delete': $id = isset($_GET['id']) ? $_GET['id'] : null; $instansiObj->find = $id; $instansiObj->delete(); header('location:?page=instansi'); break; default: require_once 'html/view.login.php'; break; } }
} } public function update() { $query = "UPDATE instansi SET instansi = :instansi , deskripsi = :deskripsi WHERE id = :find"; try { $db = DB::prepare($query); $db->execute([':instansi' => $this->instansi, ':deskripsi' => $this->deskripsi, ':find' => $this->find]); return TRUE; } catch (PDOException $e) { echo $e->getMessage(); return FALSE; } } public function delete() { $query = "DELETE FROM instansi WHERE id = :find"; try { $db = DB::prepare($query); $db->execute([':find' => $this->find]); return TRUE; } catch (PDOException $e) { echo $e->getMessage(); return FALSE; } } } $obj = new Instansi(); $obj->find = '2'; $obj->delete();