// Make sure these variables are set: if (isset($_POST['sale_price'], $_POST['start_date'], $_POST['end_date'])) { // Need the product functions: require '../includes/product_functions.inc.php'; // Prepare the query to be run: $q = 'INSERT INTO sales (product_type, product_id, price, start_date, end_date) VALUES (?, ?, ?, ?, ?)'; $stmt = mysqli_prepare($dbc, $q); mysqli_stmt_bind_param($stmt, 'sidss', $type, $id, $price, $start_date, $end_date); // Count the number of affected rows: $affected = 0; // Loop through each provided value: foreach ($_POST['sale_price'] as $sku => $price) { // Validate the price and start date: if (filter_var($price, FILTER_VALIDATE_FLOAT) && $price > 0 && !empty($_POST['start_date'][$sku])) { // Parse the SKU: list($type, $id) = parse_sku($sku); // Get the dates: $start_date = $_POST['start_date'][$sku]; $end_date = empty($_POST['end_date'][$sku]) ? NULL : $_POST['end_date'][$sku]; // Execute the query: mysqli_stmt_execute($stmt); $affected += mysqli_stmt_affected_rows($stmt); } // End of price/date validation IF. } // End of FOREACH loop. // Indicate the results: echo "<h4>{$affected} Sales Were Created!</h4>"; } // $_POST variables aren't set. }
// Remove it from the cart. $r = mysqli_query($dbc, "CALL remove_from_cart('{$uid}', '{$sp_type}', {$pid})"); } elseif (isset($sp_type, $pid, $_GET['action'], $_GET['qty']) && $_GET['action'] == 'move') { // Move it to the cart. // Determine the quantity: $qty = filter_var($_GET['qty'], FILTER_VALIDATE_INT, array('min_range' => 1)) ? $_GET['qty'] : 1; // Add it to the cart: $r = mysqli_query($dbc, "CALL add_to_cart('{$uid}', '{$sp_type}', {$pid}, {$qty})"); // Remove it from the wish list: $r = mysqli_query($dbc, "CALL remove_from_wish_list('{$uid}', '{$sp_type}', {$pid})"); } elseif (isset($_POST['quantity'])) { // Update quantities in the cart. // Loop through each item: foreach ($_POST['quantity'] as $sku => $qty) { // Parse the SKU: list($sp_type, $pid) = parse_sku($sku); if (isset($sp_type, $pid)) { // Determine the quantity: $qty = filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false ? $qty : 1; // Update the quantity in the cart: $r = mysqli_query($dbc, "CALL update_cart('{$uid}', '{$sp_type}', {$pid}, {$qty})"); } } // End of FOREACH loop. } // End of main IF. // Get the cart contents: $r = mysqli_query($dbc, "CALL get_shopping_cart_contents('{$uid}')"); if (mysqli_num_rows($r) > 0) { // Products to show! include './views/cart.html';