<?php
if (isset($_POST['discountSubmit'])) {
    // Include your database connection file
    include '../db.php';
    
    // Retrieve the form data
    $discount = mysqli_real_escape_string($con, $_POST['discount']);
    $productId = mysqli_real_escape_string($con, $_POST['productId']);
    
    // Update query
    $updateQuery = "UPDATE product SET pDiscount = '$discount' WHERE pid = '$productId'";

    if (mysqli_query($con, $updateQuery)) {
        echo "<script>
                alert('Discount updated successfully.');
                window.location = 'view-productList.php#{$productId}';
              </script>";
    } else {
        echo "<script>
                alert('Error updating discount: " . mysqli_error($con) . "');
                window.location = 'view-productList.php#{$productId}';
              </script>";
    }
    
    // Close the connection
    mysqli_close($con);
}
?>