File: /home/h278792/public_html/disc/save_discount.php
<?php
require 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $_POST['id'] ?? 0;
$full_name = $_POST['full_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$discount_code = $_POST['discount_code'];
$expires_at = $_POST['expires_at'];
if ($_GET['action'] === 'edit' && $id) {
// ویرایش
$stmt = $pdo->prepare("UPDATE discounts SET full_name = ?, phone = ?, email = ?, discount_code = ?, expires_at = ? WHERE id = ?");
$stmt->execute([$full_name, $phone, $email, $discount_code, $expires_at, $id]);
} else {
// افزودن
$stmt = $pdo->prepare("INSERT INTO discounts (full_name, phone, email, discount_code, expires_at) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$full_name, $phone, $email, $discount_code, $expires_at]);
}
header("Location: admin.php");
exit;
}
?>