'', 'price_from' => '', 'price_to' => '', 'weight_from' => '', 'weight_to' => '', 'price' => '', 'type' => 'Single Product', 'countries' => '' ]; $types = ['Single Product', 'Entire Order']; if (isset($_GET['id'])) { // ID param exists, edit an existing shipping method $page = 'Edit'; if (isset($_POST['submit'])) { // Update the shipping method $countries_list = isset($_POST['countries']) ? implode(',', $_POST['countries']) : ''; $stmt = $pdo->prepare('UPDATE shipping SET name = ?, price_from = ?, price_to = ?, weight_from = ?, weight_to = ?, price = ?, type = ?, countries = ? WHERE id = ?'); $stmt->execute([ $_POST['name'], $_POST['price_from'], $_POST['price_to'], $_POST['weight_from'], $_POST['weight_to'], $_POST['price'], $_POST['type'], $countries_list, $_GET['id'] ]); header('Location: index.php?page=shipping&success_msg=2'); exit; } if (isset($_POST['delete'])) { // Delete the shipping method $stmt = $pdo->prepare('DELETE FROM shipping WHERE id = ?'); $stmt->execute([ $_GET['id'] ]); header('Location: index.php?page=shipping&success_msg=3'); exit; } // Get the shipping method from the database $stmt = $pdo->prepare('SELECT * FROM shipping WHERE id = ?'); $stmt->execute([ $_GET['id'] ]); $shipping = $stmt->fetch(PDO::FETCH_ASSOC); } else { // Create a new shipping method $page = 'Create'; if (isset($_POST['submit'])) { $countries_list = isset($_POST['countries']) ? implode(',', $_POST['countries']) : ''; $stmt = $pdo->prepare('INSERT INTO shipping (name, price_from, price_to, weight_from, weight_to, price, type, countries) VALUES (?,?,?,?,?,?,?,?)'); $stmt->execute([ $_POST['name'], $_POST['price_from'], $_POST['price_to'], $_POST['weight_from'], $_POST['weight_to'], $_POST['price'], $_POST['type'], $countries_list ]); header('Location: index.php?page=shipping&success_msg=1'); exit; } } ?> =template_admin_header($page . ' Shipping Method', 'shipping', 'manage')?>
=template_admin_footer()?>