function MySQLUPDATE($table, $conditions, $values) { if (empty($values) || empty($table)) { return; } $query_values = array(); $query_conditions = array(); foreach ($values as $key => $value) { $query_values[] = $key . "='" . MySQLQuote($value) . "'"; } foreach ($conditions as $key => $value) { $value = MySQLQuote($value); if (is_array($value)) { $in_st = implode(',', $value); $query_conditions[] = $key . " IN(" . $in_st . ")"; } else { $query_conditions[] = $key . "='" . $value . "'"; } } $query = 'UPDATE ' . $table . ' SET ' . implode(',', $query_values); if (!empty($conditions)) { $query .= ' WHERE ' . implode(' AND ', $query_conditions); } // pd($query); MySQLExec($query); }
<?php require_once '../init.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { MySQLUPDATE('configurations', array('name' => 'company_name1'), array('value' => MySQLQuote($_POST['company_name1']))); MySQLUPDATE('configurations', array('name' => 'company_name2'), array('value' => MySQLQuote($_POST['company_name2']))); MySQLUPDATE('configurations', array('name' => 'company_bottom_fone1'), array('value' => MySQLQuote($_POST['company_bottom_fone1']))); MySQLUPDATE('configurations', array('name' => 'company_bottom_fone2'), array('value' => MySQLQuote($_POST['company_bottom_fone2']))); MySQLUPDATE('configurations', array('name' => 'company_bottom_fone3'), array('value' => MySQLQuote($_POST['company_bottom_fone3']))); MySQLUPDATE('configurations', array('name' => 'company_side_fone1'), array('value' => MySQLQuote($_POST['company_side_fone1']))); MySQLUPDATE('configurations', array('name' => 'company_side_fone2'), array('value' => MySQLQuote($_POST['company_side_fone2']))); MySQLUPDATE('configurations', array('name' => 'company_address'), array('value' => MySQLQuote($_POST['company_address']))); $_SESSION['flash']['update_company_info_ok'] = '1'; header('Location: /quanly/edit_company_info.php'); exit; } if (isset($_SESSION['flash']['update_company_info_ok'])) { $smarty->assign('update_ok', '1'); unset($_SESSION['flash']['update_company_info_ok']); } $smarty->display('admin/edit_company_info.tpl');
// $smarty = new SmartyEx; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $product_id = $_POST['product_id']; $product_category = $_POST['product_category']; $product_price = $_POST['product_price']; $product_name = $_POST['product_name']; $product_description = $_POST['product_description']; $basefilename = basename($_FILES['product_image']['name']); if (!empty($basefilename)) { $tmp_upload = UPLOADS . $basefilename; if (move_uploaded_file($_FILES['product_image']['tmp_name'], $tmp_upload)) { ResizeImage($tmp_upload, 800, 600); rename($tmp_upload . '_resized', SYS_IMAGES_PATH . $basefilename); unlink($tmp_upload); } unlink(SYS_IMAGES_PATH . $product['product_image']); MySQLUPDATE('products', array('id' => $product_id), array('product_category' => $product_category, 'product_price' => MySQLQuote($product_price), 'product_name' => MySQLQuote($product_name), 'product_image' => MySQLQuote($basefilename), 'product_description' => MySQLQuote($product_description), 'updated_date' => date('Y-m-d H:i:s'))); } else { MySQLUPDATE('products', array('id' => $product_id), array('product_category' => $product_category, 'product_price' => MySQLQuote($product_price), 'product_name' => MySQLQuote($product_name), 'product_description' => MySQLQuote($product_description), 'updated_date' => date('Y-m-d H:i:s'))); } $_SESSION['flash']['update_product_ok'] = '1'; header('Location: /quanly/product_detail.php?product_id=' . $product_id); exit; } if (isset($_SESSION['flash']['update_product_ok'])) { $smarty->assign('update_ok', '1'); unset($_SESSION['flash']['update_product_ok']); } $smarty->assign("product", $product[0]); $smarty->assign("cat_list", $cat_list); $smarty->display('admin/product_detail.tpl');
<?php require_once '../init.php'; $query = "SELECT * FROM categories WHERE deleted='0'"; $cat_list = MySQLSELECT($query); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $cat_name = $_POST['cat_name']; $cat_parent = $_POST['cat_parent']; MySQLINSERT('categories', array('category_name' => MySQLQuote($cat_name), 'category_parent' => MySQLQuote($cat_parent), 'created_date' => date('Y-m-d H:i:s'))); $_SESSION['flash']['add_category_ok'] = '1'; header('Location: /quanly/category_add.php'); exit; } // $smarty = new SmartyEx; if (isset($_SESSION['flash']['add_category_ok'])) { $smarty->assign('add_category_ok', '1'); unset($_SESSION['flash']['add_category_ok']); } $smarty->assign("cat_list", $cat_list); $smarty->display('admin/category_add.tpl');
<?php require_once '../init.php'; $query = "SELECT * FROM categories WHERE deleted='0'"; $cat_list = MySQLSELECT($query); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $product_category = $_POST['product_category']; $product_price = $_POST['product_price']; $product_name = $_POST['product_name']; $product_description = $_POST['product_description']; $basefilename = basename($_FILES['product_image']['name']); $tmp_upload = UPLOADS . $basefilename; if (move_uploaded_file($_FILES['product_image']['tmp_name'], $tmp_upload)) { ResizeImage($tmp_upload, 800, 600); rename($tmp_upload . '_resized', SYS_IMAGES_PATH . $basefilename); unlink($tmp_upload); } MySQLINSERT('products', array('product_category' => $product_category, 'product_price' => (int) MySQLQuote($product_price), 'product_name' => MySQLQuote($product_name), 'product_image' => MySQLQuote($basefilename), 'product_description' => MySQLQuote($product_description), 'created_date' => date('Y-m-d H:i:s'))); $_SESSION['flash']['add_product_ok'] = '1'; header('Location: /quanly/product_add.php'); exit; } if (isset($_SESSION['flash']['add_product_ok'])) { $smarty->assign('add_product_ok', '1'); unset($_SESSION['flash']['add_product_ok']); } // $smarty = new SmartyEx; $smarty->assign("cat_list", $cat_list); $smarty->display('admin/product_add.tpl');
<?php require_once '../init.php'; $cat_id = $_GET['cat_id']; $query = "SELECT * FROM categories WHERE deleted='0' AND id=" . MySQLQuote($cat_id); $cat = MySQLSELECT($query); $query = "SELECT * FROM categories WHERE deleted='0'"; $cat_list = MySQLSELECT($query); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $cat_id = $_POST['cat_id']; if ($_POST['submit'] == 'Lưu thay đổi') { $cat_parent = $_POST['cat_parent']; $cat_name = $_POST['cat_name']; MySQLUPDATE('categories', array('id' => $cat_id), array('category_name' => MySQLQuote($cat_name), 'category_parent' => MySQLQuote($cat_parent), 'updated_date' => date('Y-m-d H:i:s'))); } elseif ($_POST['submit'] == 'Xóa danh mục này') { $subcat = FindSubCategories($cat_id); MySQLUPDATE('categories', array('id' => $subcat), array('deleted' => "1", 'updated_date' => date('Y-m-d H:i:s'))); $query = "SELECT id FROM categories WHERE deleted='0' LIMIT 1"; $cat = MySQLSELECT($query); } $_SESSION['flash']['update_category_ok'] = '1'; header('Location: /quanly/category_detail.php?cat_id=' . $cat[0]['id']); exit; } // $smarty = new SmartyEx; if (isset($_SESSION['flash']['update_category_ok'])) { $smarty->assign('update_category_ok', '1'); unset($_SESSION['flash']['update_category_ok']); } $smarty->assign("cat_id", $cat_id); $smarty->assign("cat", $cat[0]);