function update_item() { connect_and_select_db(DB_SERVER, DB_UN, DB_PWD, DB_NAME); // Get the bannerid and other data sent by the user from the query $itemNumber = $_REQUEST['itemNumber']; $itemDescription = mysql_real_escape_string($_POST["itemDescription"]); $category = mysql_real_escape_string($_POST["category"]); $deptName = mysql_real_escape_string($_POST["departmentName"]); $purchCost = mysql_real_escape_string($_POST["purchaseCost"]); $retail = mysql_real_escape_string($_POST["retailPrice"]); $updateStmt = "update Item\n\tset ItemDescription = '" . $itemDescription . "', Category = '" . $category . "', DepartmentName = '" . $deptName . "',\n\tPurchaseCost = '" . $purchCost . "', FullRetailPrice = '" . $retail . "'" . "WHERE ItemNumber = '" . $itemNumber . "'"; $result = execute_SQL_query_with_no_error_report($updateStmt); $message = ""; if (!$result) { $message .= "Error in updating Item: " . $itemNumber . " in database.<br />" . mysql_error() . "<hr />"; } else { $message = "Data for Item updated successfully. <br />Item Number: {$itemNumber}<br />Item Description: {$itemDescription}\n<br />Category: {$category} <br />Department Name: {$deptName}<br />Purchase Cost: {$purchCost}<br\n/>Retail Price: {$retail}<br /><br />"; } $getPromoItemsStmt = "SELECT * FROM PromotionItem WHERE ItemNumber = '{$itemNumber}'"; //echo "$getPromoItemsStmt"; $promoItems = execute_SQL_query_with_no_error_report($getPromoItemsStmt); $numPromoItems = count_rows_in_result_set($promoItems); while ($promoItem = mysql_fetch_assoc($promoItems)) { $id = $promoItem['ID']; $promoCode = $promoItem['PromoCode']; $oldSalePrice = $promoItem['SalePrice']; //echo "ID = $id PromoCode: $promoCode OldSalePrice: $oldSalePrice"; $newSalePrice = getNewSalePrice($retail, $promoCode); $promoItemUpdateStmt = "UPDATE PromotionItem\n set SalePrice = '{$newSalePrice}'\n where ID = '{$id}'"; $result = execute_SQL_query_with_no_error_report($promoItemUpdateStmt); if (!$result) { $message .= "Error in updating Promotion Item: " . $id . " in database.<br />" . mysql_error() . "<hr\n />"; } else { $message .= "Data for Promotion Item with ID: " . $id . " updated successfully. <br />Old Sale Price: " . $oldSalePrice . "<br />New Sale Price: " . $newSalePrice . "<hr />"; } } ui_show_item_update_details($message); }
function update_promotion() { connect_and_select_db(DB_SERVER, DB_UN, DB_PWD, DB_NAME); // Get the bannerid and other data sent by the user from the query $promoCode = $_POST['promoCode']; $name = mysql_real_escape_string($_POST["promotionName"]); $description = mysql_real_escape_string($_POST["promotionDescription"]); $amountOff = mysql_real_escape_string($_POST["amountOff"]); $promoType = mysql_real_escape_string($_POST["promotionType"]); $updateStmt = "update Promotion\n\tset Name = '" . $name . "', Description = '" . $description . "', AmountOff = '" . $amountOff . "',\n\tPromoType = '" . $promoType . "'" . "WHERE PromoCode = '" . $promoCode . "'"; $result = execute_SQL_query_with_no_error_report($updateStmt); $message = ""; if (!$result) { $message .= "Error in updating Promotion: " . $promoCode . " in database.<br />" . mysql_error() . "<hr />"; } else { $message = "Data for Promotion updated successfully.<br />PromoCode: {$promoCode}<br />Promotion Description:\n{$description} <br />Promotion\nType:\n{$promoType} <br />Promotion Name: {$name} <br />Amount Off: {$amountOff}<br /><br />"; } $getPromoItemsStmt = "SELECT * FROM PromotionItem WHERE PromoCode = '{$promoCode}'"; //echo "$getPromoItemsStmt"; $promoItems = execute_SQL_query_with_no_error_report($getPromoItemsStmt); $numPromoItems = count_rows_in_result_set($promoItems); while ($promoItem = mysql_fetch_assoc($promoItems)) { $id = $promoItem['ID']; $oldSalePrice = $promoItem['SalePrice']; $itemNo = $promoItem['ItemNumber']; $retail = getRetailPrice($itemNo); //echo "ID = $id PromoCode: $promoCode OldSalePrice: $oldSalePrice"; $newSalePrice = getNewSalePrice($retail, $promoType, $amountOff); $promoItemUpdateStmt = "UPDATE PromotionItem\n set SalePrice = '{$newSalePrice}'\n where ID = '{$id}'"; $result = execute_SQL_query_with_no_error_report($promoItemUpdateStmt); if (!$result) { $message .= "Error in updating Promotion Item: " . $id . " in database.<br />" . mysql_error() . "<hr\n />"; } else { $message .= "Data for Promotion Item with ID: " . $id . " updated successfully. <br />Old Sale Price: " . $oldSalePrice . "<br />New Sale Price: " . $newSalePrice . "<hr />"; } } ui_show_promotion_update_details($message); }