Bladeren bron

fleat:system product files

igb 3 weken geleden
bovenliggende
commit
f84d8d2fb1
4 gewijzigde bestanden met toevoegingen van 655 en 440 verwijderingen
  1. 128 0
      system/add_product.php
  2. 187 0
      system/edit_product.php
  3. 232 440
      system/products.php
  4. 108 0
      system/save_product.php

+ 128 - 0
system/add_product.php

@@ -0,0 +1,128 @@
+<?php
+require_once('conn.php');
+require_once('functions.php');
+
+// Check login status
+checkLogin("信息管理");
+
+// Initialize variables
+$product_name = '';
+$product_img = '';
+$unit = '';
+$moq = '';
+$category_id = isset($_GET['category_id']) ? intval($_GET['category_id']) : 0;
+$note = '';
+$tips = '';
+$keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
+$page = isset($_GET['Page']) ? $_GET['Page'] : 1;
+
+// Get the return URL
+$href_str = "products.php?keys=" . $keys . "&Page=" . $page;
+if ($category_id) {
+    $href_str .= "&category_id=" . $category_id;
+}
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>添加产品</title>
+<link rel="stylesheet" href="css/common.css" type="text/css" />
+<script language="javascript" src="js/jquery-1.7.2.min.js"></script>
+<script type="text/javascript" src="js/js.js"></script>
+<script type="text/javascript" src="js/SearchArea.js"></script>
+<script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
+</head>
+
+<body>
+<div id="man_zone">
+    <form name="form1" method="post" action="save_product.php">
+        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
+            <tbody>
+                <tr>
+                    <th width="8%">产品名称</th>
+                    <td><input type="text" id="ProductName" name="ProductName" value="<?php echo $product_name; ?>" class="txt1" />
+                    <input type="hidden" name="id" value="" />
+                    <input type="hidden" name="keys" value="<?php echo $keys; ?>" />
+                    <input type="hidden" name="page" value="<?php echo $page; ?>" />
+                    <input type="hidden" name="category_id" value="<?php echo $category_id; ?>" />
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">产品分类</th>
+                    <td>
+                        <select name="category_id" id="category_id" class="select1">
+                            <option value="0">-- 请选择分类 --</option>
+                            <?php
+                            // Build category tree
+                            $category_data = buildCategoryTree($conn);
+                            $cat_tree = $category_data['tree'];
+                            
+                            // Output options
+                            outputCategoryOptions($cat_tree, $category_id);
+                            ?>
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">产品图片</th>
+                    <td><input type="text" id="ProductImg" name="ProductImg" placeholder="186x*186px" value="<?php echo $product_img; ?>" class="txt1" style="width:390px;float:left;" />
+                    <iframe src="uploadfile.php" frameborder="0" scrolling="no" style="width:400px;height:22px;float:left;margin-left:10px;"></iframe></td>
+                </tr>
+                <tr>
+                    <th width="8%">计价单位</th>
+                    <td><input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th width="8%">起订数量</th>
+                    <td><input type="text" id="moq" name="moq" value="<?php echo $moq; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th width="8%">默认售价</th>
+                    <td>
+                        <div class="Price">
+                            <div class="priceitem">
+                                <label>≥</label>
+                                <input type="number" class="txt3 num" name="num[]">
+                                <label class="unit"><?php echo $unit; ?></label>
+                                <label>售价</label>
+                                <input type="text" class="txt3 price" name="price[]">
+                                <label>RMB</label>
+                                <span class="additem"></span>
+                                <span class="delitem"></span>
+                                <span class="note"></span>
+                            </div>
+                        </div>
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">不报价地区</th>
+                    <td>
+                        <ul class="areadd"></ul>
+                        <input type="text" id="AreaSearch" class="fastsearch">
+                        <div id="arealist" class="productlist"><ul></ul></div>
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">不报价处理方式</th>
+                    <td><input type="text" id="note" name="note" value="<?php echo $note; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th width="8%">备注</th>
+                    <td><input type="text" id="tips" name="tips" value="<?php echo $tips; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th></th>
+                    <td colspan="2">
+                        <input type="submit" name="save" value="确定" class="btn1" />
+                        <input type="reset" name="reset" value="重置" class="btn1" />
+                        <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $href_str; ?>'" />
+                    </td>
+                </tr>
+            </tbody>
+        </table>
+    </form>
+</div>
+</body>
+</html>
+<?php mysqli_close($conn); ?> 

+ 187 - 0
system/edit_product.php

@@ -0,0 +1,187 @@
+<?php
+require_once('conn.php');
+require_once('functions.php');
+
+// Check login status
+checkLogin("信息管理");
+
+// Initialize variables
+$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
+$keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
+$page = isset($_GET['Page']) ? $_GET['Page'] : 1;
+$category_id = isset($_GET['category_id']) ? intval($_GET['category_id']) : 0;
+
+// Get the return URL
+$href_str = "products.php?keys=" . $keys . "&Page=" . $page;
+if ($category_id) {
+    $href_str .= "&category_id=" . $category_id;
+}
+
+// Check if the product exists
+if ($id <= 0) {
+    header("Location: " . $href_str);
+    exit();
+}
+
+// Fetch product data
+$sql = "SELECT * FROM products WHERE id = " . (int)$id;
+$result = mysqli_query($conn, $sql);
+
+if (mysqli_num_rows($result) <= 0) {
+    // Product not found, redirect
+    header("Location: " . $href_str);
+    exit();
+}
+
+$row = mysqli_fetch_assoc($result);
+$product_name = htmlspecialcharsFix($row['ProductName']);
+$product_img = htmlspecialcharsFix($row['ProductImg']);
+$unit = htmlspecialcharsFix($row['unit']);
+$moq = htmlspecialcharsFix($row['moq']);
+$nosale = $row['nosale'];
+$note = htmlspecialcharsFix($row['note']);
+$tips = htmlspecialcharsFix($row['tips']);
+$category_id = $row['category_id'] ? intval($row['category_id']) : 0;
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>编辑产品</title>
+<link rel="stylesheet" href="css/common.css" type="text/css" />
+<script language="javascript" src="js/jquery-1.7.2.min.js"></script>
+<script type="text/javascript" src="js/js.js"></script>
+<script type="text/javascript" src="js/SearchArea.js"></script>
+<script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
+</head>
+
+<body>
+<div id="man_zone">
+    <form name="form1" method="post" action="save_product.php">
+        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
+            <tbody>
+                <tr>
+                    <th width="8%">产品名称</th>
+                    <td><input type="text" id="ProductName" name="ProductName" value="<?php echo $product_name; ?>" class="txt1" />
+                    <input type="hidden" name="id" value="<?php echo $id; ?>" />
+                    <input type="hidden" name="keys" value="<?php echo $keys; ?>" />
+                    <input type="hidden" name="page" value="<?php echo $page; ?>" />
+                    <input type="hidden" name="category_id" value="<?php echo $category_id; ?>" />
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">产品分类</th>
+                    <td>
+                        <select name="category_id" id="category_id" class="select1">
+                            <option value="0">-- 请选择分类 --</option>
+                            <?php
+                            // Build category tree
+                            $category_data = buildCategoryTree($conn);
+                            $cat_tree = $category_data['tree'];
+                            
+                            // Output options
+                            outputCategoryOptions($cat_tree, $category_id);
+                            ?>
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">产品图片</th>
+                    <td><input type="text" id="ProductImg" name="ProductImg" placeholder="186x*186px" value="<?php echo $product_img; ?>" class="txt1" style="width:390px;float:left;" />
+                    <iframe src="uploadfile.php" frameborder="0" scrolling="no" style="width:400px;height:22px;float:left;margin-left:10px;"></iframe></td>
+                </tr>
+                <tr>
+                    <th width="8%">计价单位</th>
+                    <td><input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th width="8%">起订数量</th>
+                    <td><input type="text" id="moq" name="moq" value="<?php echo $moq; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th width="8%">默认售价</th>
+                    <td>
+                        <div class="Price">
+                        <?php
+                        $price_sql = "SELECT num, price FROM price WHERE AreaId = 0 AND productId = " . $id . " ORDER BY num ASC";
+                        $price_result = mysqli_query($conn, $price_sql);
+                        if (mysqli_num_rows($price_result) > 0) {
+                            while ($price_row = mysqli_fetch_assoc($price_result)) {
+                                ?>
+                                <div class="priceitem">
+                                    <label>≥</label>
+                                    <input type="number" class="txt3 num" name="num[]" value="<?php echo $price_row['num']; ?>">
+                                    <label class="unit"><?php echo $unit; ?></label>
+                                    <label>售价</label>
+                                    <input type="text" class="txt3 price" name="price[]" value="<?php echo $price_row['price']; ?>">
+                                    <label>RMB</label>
+                                    <span class="additem"></span>
+                                    <span class="delitem"></span>
+                                    <span class="note"></span>
+                                </div>
+                                <?php
+                            }
+                        } else {
+                            ?>
+                            <div class="priceitem">
+                                <label>≥</label>
+                                <input type="number" class="txt3 num" name="num[]">
+                                <label class="unit"><?php echo $unit; ?></label>
+                                <label>售价</label>
+                                <input type="text" class="txt3 price" name="price[]">
+                                <label>RMB</label>
+                                <span class="additem"></span>
+                                <span class="delitem"></span>
+                                <span class="note"></span>
+                            </div>
+                            <?php
+                        }
+                        ?>
+                        </div>
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">不报价地区</th>
+                    <td>
+                        <ul class="areadd">
+                        <?php
+                        if (!empty($nosale)) {
+                            // 确保nosale是逗号分隔的字符串格式
+                            $nosale_str = is_array($nosale) ? implode(',', $nosale) : $nosale;
+                            $area_sql = "SELECT id, countryName FROM country WHERE id IN(" . $nosale_str . ")";
+                            $area_result = mysqli_query($conn, $area_sql);
+                            while ($area_row = mysqli_fetch_assoc($area_result)) {
+                                ?>
+                                <li><input type="hidden" name="nosale[]" value="<?php echo $area_row['id']; ?>"><span class="cname"><?php echo htmlspecialcharsFix($area_row['countryName']); ?></span><span class="close"></span></li>
+                                <?php
+                            }
+                        }
+                        ?>
+                        </ul>
+                        <input type="text" id="AreaSearch" class="fastsearch">
+                        <div id="arealist" class="productlist"><ul></ul></div>
+                    </td>
+                </tr>
+                <tr>
+                    <th width="8%">不报价处理方式</th>
+                    <td><input type="text" id="note" name="note" value="<?php echo $note; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th width="8%">备注</th>
+                    <td><input type="text" id="tips" name="tips" value="<?php echo $tips; ?>" class="txt1"/></td>
+                </tr>
+                <tr>
+                    <th></th>
+                    <td colspan="2">
+                        <input type="submit" name="save" value="确定" class="btn1" />
+                        <input type="reset" name="reset" value="重置" class="btn1" />
+                        <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $href_str; ?>'" />
+                    </td>
+                </tr>
+            </tbody>
+        </table>
+    </form>
+</div>
+</body>
+</html>
+<?php mysqli_close($conn); ?> 

+ 232 - 440
system/products.php

@@ -1,101 +1,28 @@
 <?php
 require_once('conn.php');
 
-
 // Check login status (assuming you have a similar function in PHP)
 checkLogin("信息管理");
 
 // Initialize all variables to avoid undefined warnings
 $act = isset($_GET['act']) ? $_GET['act'] : '';
-$product_name = isset($_POST['ProductName']) ? htmlspecialcharsFix($_POST['ProductName']) : '';
-$product_img = isset($_POST['ProductImg']) ? htmlspecialcharsFix($_POST['ProductImg']) : '';
-$unit = isset($_POST['unit']) ? htmlspecialcharsFix($_POST['unit']) : '';
-$moq = isset($_POST['moq']) ? htmlspecialcharsFix($_POST['moq']) : '';
-$category_id = isset($_POST['category_id']) ? intval($_POST['category_id']) : (isset($_GET['category_id']) ? intval($_GET['category_id']) : 0);
-$nosale = isset($_POST['nosale']) ? $_POST['nosale'] : array();
-$num = isset($_POST['num']) ? $_POST['num'] : array();
-$price = isset($_POST['price']) ? $_POST['price'] : array();
-$note = isset($_POST['note']) ? htmlspecialcharsFix($_POST['note']) : '';
-$tips = isset($_POST['tips']) ? htmlspecialcharsFix($_POST['tips']) : '';
 $page = isset($_GET['Page']) ? $_GET['Page'] : 1;
 $keys = isset($_GET['Keys']) ? urlencode($_GET['Keys']) : '';
 $keyscode = isset($_GET['Keys']) ? htmlspecialcharsFix($_GET['Keys']) : '';
+$category_id = isset($_GET['category_id']) ? intval($_GET['category_id']) : 0;
 
 // Handle form submissions and redirects before any output
-if ($act == 'save') {
-    $id = isset($_POST['id']) ? $_POST['id'] : '';
-    $is_edit = (!empty($id) && is_numeric($id));
-    
-    // Process nosale array into comma-separated string
-    $nosale_str = '';
-    if (is_array($nosale) && !empty($nosale)) {
-        $nosale_clean = array_map('intval', $nosale); // Ensure all values are integers
-        $nosale_str = implode(',', $nosale_clean);
-    }
-    
-    if ($is_edit) {
-        // Update existing product
-        $sql = "UPDATE products SET 
-                ProductName = '" . mysqli_real_escape_string($conn, $product_name) . "',
-                ProductImg = '" . mysqli_real_escape_string($conn, $product_img) . "',
-                Addtime = NOW(),
-                moq = '" . mysqli_real_escape_string($conn, $moq) . "',
-                unit = '" . mysqli_real_escape_string($conn, $unit) . "',
-                nosale = '" . $nosale_str . "',
-                note = '" . mysqli_real_escape_string($conn, $note) . "',
-                tips = '" . mysqli_real_escape_string($conn, $tips) . "',
-                category_id = " . $category_id . "
-                WHERE id = " . (int)$id;
-        mysqli_query($conn, $sql);
-        
-        // Handle price updates
-        mysqli_query($conn, "DELETE FROM price WHERE productId = " . (int)$id . " AND AreaId = 0");
-        
-        if (is_array($num) && is_array($price)) {
-            foreach ($num as $key => $num_value) {
-                if (isset($price[$key])) { // Only process if we have both num and price
-                    $num_value = empty($num_value) ? 0 : (float)$num_value;
-                    $price_value = empty($price[$key]) ? 0 : (float)$price[$key];
-                    $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES 
-                            (" . (int)$id . ", 0, " . $num_value . ", '" . $price_value . "')";
-                    mysqli_query($conn, $sql);
-                }
-            }
-        }
-    } else {
-        // Insert new product
-        $sql = "INSERT INTO products (ProductName, ProductImg, Addtime, moq, unit, nosale, note, tips, category_id) 
-                VALUES (
-                    '" . mysqli_real_escape_string($conn, $product_name) . "',
-                    '" . mysqli_real_escape_string($conn, $product_img) . "',
-                    NOW(),
-                    '" . mysqli_real_escape_string($conn, $moq) . "',
-                    '" . mysqli_real_escape_string($conn, $unit) . "',
-                    '" . $nosale_str . "',
-                    '" . mysqli_real_escape_string($conn, $note) . "',
-                    '" . mysqli_real_escape_string($conn, $tips) . "',
-                    " . $category_id . "
-                )";
-        mysqli_query($conn, $sql);
-        $id = mysqli_insert_id($conn);
-        
-        // Handle price insertions
-        if (is_array($num) && is_array($price)) {
-            foreach ($num as $key => $num_value) {
-                if (isset($price[$key])) { // Only process if we have both num and price
-                    $num_value = empty($num_value) ? 0 : (float)$num_value;
-                    $price_value = empty($price[$key]) ? 0 : (float)$price[$key];
-                    $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES 
-                            (" . (int)$id . ", 0, " . $num_value . ", '" . $price_value . "')";
-                    mysqli_query($conn, $sql);
-                }
-            }
-        }
-    }
-    
-    // Redirect after save
-    header("Location: ?keys=" . $keys . "&Page=" . $page);
+if ($act == 'add') {
+    // Redirect to the add product page
+    header("Location: add_product.php?Keys=" . $keys . "&Page=" . $page . ($category_id ? "&category_id=" . $category_id : ""));
     exit();
+} else if ($act == 'edit') {
+    $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
+    if ($id > 0) {
+        // Redirect to the edit product page
+        header("Location: edit_product.php?id=" . $id . "&Keys=" . $keys . "&Page=" . $page . ($category_id ? "&category_id=" . $category_id : ""));
+        exit();
+    }
 }
 
 // Handle bulk actions
@@ -122,7 +49,7 @@ if ($act == 'postchk') {
             }
         }
         
-        header("Location: ?Keys=" . $keys . "&Page=" . $page);
+        header("Location: ?Keys=" . $keys . "&Page=" . $page . ($category_id ? "&category_id=" . $category_id : ""));
         exit();
     }
 }
@@ -189,378 +116,243 @@ if ($act == 'postchk') {
 <body>
 <div id="man_zone">
 <?php
-// Handle add/edit form display
-if ($act == 'add' || $act == 'edit') {
-    $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
-    $is_edit = ($id > 0);
-    
-    if ($is_edit) {
-        $sql = "SELECT * FROM products WHERE id = " . (int)$id;
-        $result = mysqli_query($conn, $sql);
-        
-        if (mysqli_num_rows($result) > 0) {
-            $row = mysqli_fetch_assoc($result);
-            $product_name = htmlspecialcharsFix($row['ProductName']);
-            $product_img = htmlspecialcharsFix($row['ProductImg']);
-            $unit = htmlspecialcharsFix($row['unit']);
-            $moq = htmlspecialcharsFix($row['moq']);
-            $nosale = $row['nosale'];
-            $note = htmlspecialcharsFix($row['note']);
-            $tips = htmlspecialcharsFix($row['tips']);
-            $category_id = $row['category_id'] ? intval($row['category_id']) : 0;
-        } else {
-            // Product not found, redirect
-            header("Location: ?Keys=" . $keys . "&Page=" . $page);
-            exit();
-        }
-    }
-    
-    $href_str = "?keys=" . $keys . "&Page=" . $page;
-    ?>
-    <form name="form1" method="post" action="<?php echo $href_str; ?>&act=save">
-        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
-            <tbody>
-                <tr>
-                    <th width="8%">产品名称</th>
-                    <td><input type="text" id="ProductName" name="ProductName" value="<?php echo $product_name; ?>" class="txt1" />
-                    <input type="hidden" name="id" value="<?php echo $id; ?>" /></td>
-                </tr>
-                <tr>
-                    <th width="8%">产品分类</th>
-                    <td>
-                        <select name="category_id" id="category_id" class="select1">
-                            <option value="0">-- 请选择分类 --</option>
-                            <?php
-                            // Include the category display functions
-                            require_once 'functions.php';
-                            
-                            // Build category tree
-                            $category_data = buildCategoryTree($conn);
-                            $cat_tree = $category_data['tree'];
-                            
-                            // Output options
-                            outputCategoryOptions($cat_tree, $category_id);
-                            ?>
-                        </select>
-                    </td>
-                </tr>
-                <tr>
-                    <th width="8%">产品图片</th>
-                    <td><input type="text" id="ProductImg" name="ProductImg" placeholder="186x*186px" value="<?php echo $product_img; ?>" class="txt1" style="width:390px;float:left;" />
-                    <iframe src="uploadfile.php" frameborder="0" scrolling="no" style="width:400px;height:22px;float:left;margin-left:10px;"></iframe></td>
-                </tr>
-                <tr>
-                    <th width="8%">计价单位</th>
-                    <td><input type="text" id="unit" name="unit" value="<?php echo $unit; ?>" class="txt1"/></td>
-                </tr>
-                <tr>
-                    <th width="8%">起订数量</th>
-                    <td><input type="text" id="moq" name="moq" value="<?php echo $moq; ?>" class="txt1"/></td>
-                </tr>
-                <tr>
-                    <th width="8%">默认售价</th>
-                    <td>
-                        <div class="Price">
-                        <?php
-                        if ($is_edit) {
-                            $price_sql = "SELECT num, price FROM price WHERE AreaId = 0 AND productId = " . $id . " ORDER BY num ASC";
-                            $price_result = mysqli_query($conn, $price_sql);
-                            if (mysqli_num_rows($price_result) > 0) {
-                                while ($price_row = mysqli_fetch_assoc($price_result)) {
-                                    ?>
-                                    <div class="priceitem">
-                                        <label>≥</label>
-                                        <input type="number" class="txt3 num" name="num[]" value="<?php echo $price_row['num']; ?>">
-                                        <label class="unit"><?php echo $unit; ?></label>
-                                        <label>售价</label>
-                                        <input type="text" class="txt3 price" name="price[]" value="<?php echo $price_row['price']; ?>">
-                                        <label>RMB</label>
-                                        <span class="additem"></span>
-                                        <span class="delitem"></span>
-                                        <span class="note"></span>
-                                    </div>
-                                    <?php
-                                }
-                            }
-                        }
-                        if (!$is_edit || mysqli_num_rows($price_result) == 0) {
-                            ?>
-                            <div class="priceitem">
-                                <label>≥</label>
-                                <input type="number" class="txt3 num" name="num[]">
-                                <label class="unit"><?php echo $unit; ?></label>
-                                <label>售价</label>
-                                <input type="text" class="txt3 price" name="price[]">
-                                <label>RMB</label>
-                                <span class="additem"></span>
-                                <span class="delitem"></span>
-                                <span class="note"></span>
-                            </div>
-                            <?php
-                        }
-                        ?>
-                        </div>
-                    </td>
-                </tr>
-                <tr>
-                    <th width="8%">不报价地区</th>
-                    <td>
-                        <ul class="areadd">
-                        <?php
-                        if (!empty($nosale)) {
-                            // 确保nosale是逗号分隔的字符串格式
-                            $nosale_str = is_array($nosale) ? implode(',', $nosale) : $nosale;
-                            $area_sql = "SELECT id, countryName FROM country WHERE id IN(" . $nosale_str . ")";
-                            $area_result = mysqli_query($conn, $area_sql);
-                            while ($area_row = mysqli_fetch_assoc($area_result)) {
-                                ?>
-                                <li><input type="hidden" name="nosale[]" value="<?php echo $area_row['id']; ?>"><span class="cname"><?php echo htmlspecialcharsFix($area_row['countryName']); ?></span><span class="close"></span></li>
-                                <?php
-                            }
-                        }
-                        ?>
-                        </ul>
-                        <input type="text" id="AreaSearch" class="fastsearch">
-                        <div id="arealist" class="productlist"><ul></ul></div>
-                    </td>
-                </tr>
-                <tr>
-                    <th width="8%">不报价处理方式</th>
-                    <td><input type="text" id="note" name="note" value="<?php echo $note; ?>" class="txt1"/></td>
-                </tr>
-                <tr>
-                    <th width="8%">备注</th>
-                    <td><input type="text" id="tips" name="tips" value="<?php echo $tips; ?>" class="txt1"/></td>
-                </tr>
-                <tr>
-                    <th></th>
-                    <td colspan="2">
-                        <input type="submit" name="save" value="确定" class="btn1" />
-                        <input type="reset" name="reset" value="重置" class="btn1" />
-                        <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $href_str; ?>'" />
-                    </td>
-                </tr>
-            </tbody>
-        </table>
-    </form>
-    <?php
-} else {
-    // Display product list
-    require_once 'functions.php';
-    
-    // Get filter category id
-    $filter_category_id = isset($_GET['category_id']) ? intval($_GET['category_id']) : 0;
-    
-    // Prepare SQL condition for category filtering
-    $category_condition = '';
-    if ($filter_category_id > 0) {
-        // Get all subcategories of the selected category
-        $category_data = buildCategoryTree($conn);
-        $all_categories = $category_data['all_categories'];
-        
-        $category_ids = array($filter_category_id);
-        getSubcategoryIds($all_categories, $filter_category_id, $category_ids);
-        
-        $category_condition = " WHERE category_id IN (" . implode(',', $category_ids) . ")";
-    }
-    
-    // Search condition
-    $search_condition = '';
-    if (!empty($keyscode)) {
-        $search_condition = ($category_condition ? " AND " : " WHERE ") . 
-                           "ProductName LIKE '%" . mysqli_real_escape_string($conn, $keyscode) . "%'";
-    }
-    
-    // Get total records count using a COUNT query instead of fetching all records
-    $count_sql = "SELECT COUNT(*) as total FROM products" . $category_condition . $search_condition;
-    $count_result = mysqli_query($conn, $count_sql);
-    $count_row = mysqli_fetch_assoc($count_result);
-    $total_records = $count_row['total'];
-    
-    // 固定每页显示18条记录(与 customers.php 保持一致)
-    $pageSize = 18;
-    $total_pages = ceil($total_records / $pageSize);
-    if ($total_pages < 1) $total_pages = 1; // 确保至少有一页,即使没有结果
-    
-    // Validate page number
-    if (empty($page)) $page = 1;
-    if ($page == 'end') $page = $total_pages;
-    if (!is_numeric($page) || $page < 1) $page = 1;
-    $page = (int)$page;
-    if ($page > $total_pages) $page = $total_pages;
-    
-    // Apply pagination
-    $offset = ($page - 1) * $pageSize;
-    if ($offset < 0) $offset = 0; // 确保偏移量不为负数
+// Display product list
+require_once 'functions.php';
+
+// Get filter category id
+$filter_category_id = $category_id;
+
+// Prepare SQL condition for category filtering
+$category_condition = '';
+if ($filter_category_id > 0) {
+    // Get all subcategories of the selected category
+    $category_data = buildCategoryTree($conn);
+    $all_categories = $category_data['all_categories'];
     
-    // Fetch only the records for the current page
-    $sql = "SELECT id, ProductName, ProductImg, category_id FROM products" . 
-           $category_condition . $search_condition . " ORDER BY id DESC LIMIT $offset, $pageSize";
-    $result = mysqli_query($conn, $sql);
+    $category_ids = array($filter_category_id);
+    getSubcategoryIds($all_categories, $filter_category_id, $category_ids);
     
-    $temp_num = $pageSize * ($page - 1);
-    ?>
-    <div class="search_panel">
-        <form method="get" action="">
-            <input type="hidden" name="Page" value="1">
-            <div style="display: flex; margin-bottom: 10px;style="margin-left: 20px;"">
+    $category_condition = " WHERE category_id IN (" . implode(',', $category_ids) . ")";
+}
+
+// Search condition
+$search_condition = '';
+if (!empty($keyscode)) {
+    $search_condition = ($category_condition ? " AND " : " WHERE ") . 
+                       "ProductName LIKE '%" . mysqli_real_escape_string($conn, $keyscode) . "%'";
+}
+
+// Get total records count using a COUNT query instead of fetching all records
+$count_sql = "SELECT COUNT(*) as total FROM products" . $category_condition . $search_condition;
+$count_result = mysqli_query($conn, $count_sql);
+$count_row = mysqli_fetch_assoc($count_result);
+$total_records = $count_row['total'];
+
+// 固定每页显示18条记录(与 customers.php 保持一致)
+$pageSize = 18;
+$total_pages = ceil($total_records / $pageSize);
+if ($total_pages < 1) $total_pages = 1; // 确保至少有一页,即使没有结果
+
+// Validate page number
+if (empty($page)) $page = 1;
+if ($page == 'end') $page = $total_pages;
+if (!is_numeric($page) || $page < 1) $page = 1;
+$page = (int)$page;
+if ($page > $total_pages) $page = $total_pages;
+
+// Apply pagination
+$offset = ($page - 1) * $pageSize;
+if ($offset < 0) $offset = 0; // 确保偏移量不为负数
+
+// Fetch only the records for the current page
+$sql = "SELECT id, ProductName, ProductImg, category_id FROM products" . 
+       $category_condition . $search_condition . " ORDER BY id DESC LIMIT $offset, $pageSize";
+$result = mysqli_query($conn, $sql);
+
+$temp_num = $pageSize * ($page - 1);
+?>
+<div class="search_panel">
+    <form method="get" action="">
+        <input type="hidden" name="Page" value="1">
+        <div style="display: flex; margin-bottom: 10px;style="margin-left: 20px;"">
+        <div style="margin-right: 20px;">
+            <input type="button" value="+ 新增产品" onClick="location.href='?act=add<?php echo $filter_category_id ? '&category_id='.$filter_category_id : ''; ?>'" class="add_btn" />
+        </div>
             <div style="margin-right: 20px;">
-                <input type="button" value="+ 新增产品" onClick="location.href='?act=add<?php echo $filter_category_id ? '&category_id='.$filter_category_id : ''; ?>'" class="add_btn" />
+                <label>按分类筛选:</label>
+                <select name="category_id" class="select1" onchange="this.form.submit()">
+                    <option value="0">-- 所有分类 --</option>
+                    <?php
+                    // Build category tree for filter dropdown
+                    $category_data = buildCategoryTree($conn);
+                    $cat_tree = $category_data['tree'];
+                    
+                    // Output options
+                    outputCategoryOptions($cat_tree, $filter_category_id);
+                    ?>
+                </select>
             </div>
-                <div style="margin-right: 20px;">
-                    <label>按分类筛选:</label>
-                    <select name="category_id" class="select1" onchange="this.form.submit()">
-                        <option value="0">-- 所有分类 --</option>
-                        <?php
-                        // Build category tree for filter dropdown
-                        $category_data = buildCategoryTree($conn);
-                        $cat_tree = $category_data['tree'];
-                        
-                        // Output options
-                        outputCategoryOptions($cat_tree, $filter_category_id);
-                        ?>
-                    </select>
-                </div>
-                <div>
-                    <label>关键词搜索:</label>
-                    <input type="text" name="Keys" value="<?php echo $keyscode; ?>" class="inputTxt" placeholder="请输入产品名称">
-                    <input type="submit" value="搜索" class="searchgo">
-                </div>
-
+            <div>
+                <label>关键词搜索:</label>
+                <input type="text" name="Keys" value="<?php echo $keyscode; ?>" class="inputTxt" placeholder="请输入产品名称">
+                <input type="submit" value="搜索" class="searchgo">
             </div>
-        </form>
-    </div>
-    <form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?><?php echo $filter_category_id ? '&category_id='.$filter_category_id : ''; ?>" onSubmit="return false">
-        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
-            <thead>
-                <tr>
-                    <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
-                    <th width="6%">序号</th>
-                    <th width="25%">产品名称</th>
-                    <th width="15%">产品分类</th>
-                    <th width="30%">图片</th>
-                    <th width="20%">操作</th>
-                </tr>
-            </thead>
-            <tbody>
-            <?php
-            if (mysqli_num_rows($result) > 0) {
-                $temp_num = $pageSize * ($page - 1);
-                while ($row = mysqli_fetch_assoc($result)) {
-                    $temp_num++;
-                    ?>
-                    <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
-                        <td align="center"><input type="checkbox" name="chkbox[]" value="<?php echo $row['id']; ?>" /></td>
-                        <td align="center"><?php echo $temp_num; ?></td>
-                        <td align="center"><?php echo htmlspecialcharsFix($row['ProductName']); ?></td>
-                        <td align="center">
-                            <?php 
-                            require_once 'functions.php';
-                            echo getCategoryPath($conn, $row['category_id']); 
-                            ?>
-                        </td>
-                        <td align="center"><img src="<?php echo htmlspecialcharsFix($row['ProductImg']); ?>" width="30px"></td>
-                        <td align="center">
-                            <a href="?Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?>&act=edit&id=<?php echo $row['id']; ?>" class="ico_edit ico">修改</a>
-                        </td>
-                    </tr>
-                    <?php
-                }
-            } else {
+
+        </div>
+    </form>
+</div>
+
+<form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?><?php echo $filter_category_id ? '&category_id='.$filter_category_id : ''; ?>">
+    <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
+        <thead>
+            <tr>
+                <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
+                <th width="6%">序号</th>
+                <th width="25%">产品名称</th>
+                <th width="15%">产品分类</th>
+                <th width="30%">图片</th>
+                <th width="20%">操作</th>
+            </tr>
+        </thead>
+        <tbody>
+        <?php
+        if (mysqli_num_rows($result) > 0) {
+            $temp_num = $pageSize * ($page - 1);
+            while ($row = mysqli_fetch_assoc($result)) {
+                $temp_num++;
                 ?>
-                <tr>
-                    <td colspan="9" align="center">
-                        <?php echo empty($keys) ? 'Sorry,当前暂无信息' : '<a href="?">Sorry,没有找到"' . htmlspecialcharsFix($keyscode) . '"相关的信息,点击返回</a>'; ?>
+                <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
+                    <td align="center"><input type="checkbox" name="chkbox[]" value="<?php echo $row['id']; ?>" /></td>
+                    <td align="center"><?php echo $temp_num; ?></td>
+                    <td align="center"><?php echo htmlspecialcharsFix($row['ProductName']); ?></td>
+                    <td align="center">
+                        <?php 
+                        require_once 'functions.php';
+                        echo getCategoryPath($conn, $row['category_id']); 
+                        ?>
+                    </td>
+                    <td align="center"><img src="<?php echo htmlspecialcharsFix($row['ProductImg']); ?>" width="30px"></td>
+                    <td align="center">
+                        <a href="?Keys=<?php echo $keys; ?>&Page=<?php echo $page; ?>&act=edit&id=<?php echo $row['id']; ?><?php echo $filter_category_id ? '&category_id='.$filter_category_id : ''; ?>" class="ico_edit ico">修改</a>
                     </td>
                 </tr>
                 <?php
             }
+        } else {
             ?>
-            </tbody>
-            <tfoot>
-                <tr>
-                    <td colspan="9">
-                        <div class="showpagebox">
-                        <?php
-                        if ($total_pages > 1) {
-                            // Build page URL with all parameters
-                            $page_params = array();
-                            if (!empty($keys)) $page_params[] = "Keys=" . urlencode($keys);
-                            if ($filter_category_id > 0) $page_params[] = "category_id=" . $filter_category_id;
-                            
-                            $page_name = "?" . implode("&", $page_params) . ($page_params ? "&" : "");
-                            $page_len = 3;
-                            
-                            // Previous page links
-                            if ($page > 1) {
-                                echo "<a href=\"{$page_name}Page=1\">首页</a>";
-                                echo "<a href=\"{$page_name}Page=" . ($page-1) . "\">上一页</a>";
-                            }
-                            
-                            // Calculate page range
-                            if ($page_len * 2 + 1 >= $total_pages) {
+            <tr>
+                <td colspan="9" align="center">
+                    <?php echo empty($keys) ? 'Sorry,当前暂无信息' : '<a href="?">Sorry,没有找到"' . htmlspecialcharsFix($keyscode) . '"相关的信息,点击返回</a>'; ?>
+                </td>
+            </tr>
+            <?php
+        }
+        ?>
+        </tbody>
+        <tfoot>
+            <tr>
+                <td colspan="9">
+                    <div class="showpagebox">
+                    <?php
+                    if ($total_pages > 1) {
+                        // Build page URL with all parameters
+                        $page_params = array();
+                        if (!empty($keys)) $page_params[] = "Keys=" . urlencode($keys);
+                        if ($filter_category_id > 0) $page_params[] = "category_id=" . $filter_category_id;
+                        
+                        $page_name = "?" . implode("&", $page_params) . ($page_params ? "&" : "");
+                        $page_len = 3;
+                        
+                        // Previous page links
+                        if ($page > 1) {
+                            echo "<a href=\"{$page_name}Page=1\">首页</a>";
+                            echo "<a href=\"{$page_name}Page=" . ($page-1) . "\">上一页</a>";
+                        }
+                        
+                        // Calculate page range
+                        if ($page_len * 2 + 1 >= $total_pages) {
+                            $start_page = 1;
+                            $end_page = $total_pages;
+                        } else {
+                            if ($page <= $page_len + 1) {
                                 $start_page = 1;
-                                $end_page = $total_pages;
+                                $end_page = $page_len * 2 + 1;
                             } else {
-                                if ($page <= $page_len + 1) {
-                                    $start_page = 1;
-                                    $end_page = $page_len * 2 + 1;
-                                } else {
-                                    $start_page = $page - $page_len;
-                                    $end_page = $page + $page_len;
-                                }
-                                if ($page + $page_len > $total_pages) {
-                                    $start_page = $total_pages - $page_len * 2;
-                                    $end_page = $total_pages;
-                                }
+                                $start_page = $page - $page_len;
+                                $end_page = $page + $page_len;
                             }
-                            
-                            // Page numbers
-                            for ($i = $start_page; $i <= $end_page; $i++) {
-                                if ($i == $page) {
-                                    echo "<a class=\"current\">$i</a>";
-                                } else {
-                                    echo "<a href=\"{$page_name}Page=$i\">$i</a>";
-                                }
+                            if ($page + $page_len > $total_pages) {
+                                $start_page = $total_pages - $page_len * 2;
+                                $end_page = $total_pages;
                             }
-                            
-                            // Next page links
-                            if ($page < $total_pages) {
-                                if ($total_pages - $page > $page_len) {
-                                    echo "<a href=\"{$page_name}Page=$total_pages\">...$total_pages</a>";
-                                }
-                                echo "<a href=\"{$page_name}Page=" . ($page+1) . "\">下一页</a>";
-                                echo "<a href=\"{$page_name}Page=$total_pages\">尾页</a>";
+                        }
+                        
+                        // Page numbers
+                        for ($i = $start_page; $i <= $end_page; $i++) {
+                            if ($i == $page) {
+                                echo "<a class=\"current\">$i</a>";
+                            } else {
+                                echo "<a href=\"{$page_name}Page=$i\">$i</a>";
                             }
-                            
-                            // Jump to page input
-                            echo "<input type=\"text\" id=\"Pagego\" value=\"$page\" 
-                                  onFocus=\"if(this.value == '$page'){this.value='';}\" 
-                                  onBlur=\"if(this.value == ''){this.value='$page';}\" 
-                                  onKeyUp=\"this.value=this.value.replace(/\D/g,'')\" 
-                                  onKeyDown=\"if(event.keyCode==13){location.href='{$page_name}Page='+document.getElementById('Pagego').value}\" />";
                         }
-                        ?>
-                        </div>
                         
-                        <div class="postchkbox">
-                            <select id="chkact" name="chkact">
-                                <option value="1">显示</option>
-                                <option value="0">隐藏</option>
-                                <option value="-1">删除</option>
-                            </select>
-                            <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
-                            <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
-                        </div>
-                    </td>
-                </tr>
-            </tfoot>
-        </table>
-    </form>
-    <?php
-}
-mysqli_close($conn);
-?>
+                        // Next page links
+                        if ($page < $total_pages) {
+                            if ($total_pages - $page > $page_len) {
+                                echo "<a href=\"{$page_name}Page=$total_pages\">...$total_pages</a>";
+                            }
+                            echo "<a href=\"{$page_name}Page=" . ($page+1) . "\">下一页</a>";
+                            echo "<a href=\"{$page_name}Page=$total_pages\">尾页</a>";
+                        }
+                        
+                        // Jump to page input
+                        echo "<input type=\"text\" id=\"Pagego\" value=\"$page\" 
+                              onFocus=\"if(this.value == '$page'){this.value='';}\" 
+                              onBlur=\"if(this.value == ''){this.value='$page';}\" 
+                              onKeyUp=\"this.value=this.value.replace(/\D/g,'')\" 
+                              onKeyDown=\"if(event.keyCode==13){location.href='{$page_name}Page='+document.getElementById('Pagego').value}\" />";
+                    }
+                    ?>
+                    </div>
+                    
+                    <div class="postchkbox">
+                        <select id="chkact" name="chkact">
+
+                            <option value="-1">删除</option>
+                        </select>
+                        <input type="button" value="执行" onClick="postchk_products(1)" class="btn1" />
+                        <input type="button" value="新增" onClick="location.href='?act=add<?php echo $filter_category_id ? '&category_id='.$filter_category_id : ''; ?>'" class="btn1" />
+                    </div>
+                </td>
+            </tr>
+        </tfoot>
+    </table>
+</form>
 </div>
+<script type="application/javascript">
+
+    function postchk_products(formBtn) {
+        // Check if at least one checkbox is selected
+        var checkboxes = document.getElementsByName('chkbox[]');
+        var isChecked = false;
+
+        for (var i = 0; i < checkboxes.length; i++) {
+            if (checkboxes[i].checked) {
+                isChecked = true;
+                break;
+            }
+        }
+
+        if (!isChecked) {
+            alert('请至少选择一条数据');
+            return false;
+        }
+
+        // If at least one checkbox is selected, submit the form
+        document.getElementById('form1').submit();
+        return true;
+    }
+</script>
 </body>
-</html> 
+</html>
+<?php mysqli_close($conn); ?> 

+ 108 - 0
system/save_product.php

@@ -0,0 +1,108 @@
+<?php
+require_once('conn.php');
+
+// Check login status
+checkLogin("信息管理");
+
+// Initialize all variables to avoid undefined warnings
+$id = isset($_POST['id']) ? $_POST['id'] : '';
+$product_name = isset($_POST['ProductName']) ? htmlspecialcharsFix($_POST['ProductName']) : '';
+$product_img = isset($_POST['ProductImg']) ? htmlspecialcharsFix($_POST['ProductImg']) : '';
+$unit = isset($_POST['unit']) ? htmlspecialcharsFix($_POST['unit']) : '';
+$moq = isset($_POST['moq']) ? htmlspecialcharsFix($_POST['moq']) : '';
+$category_id = isset($_POST['category_id']) ? intval($_POST['category_id']) : 0;
+$nosale = isset($_POST['nosale']) ? $_POST['nosale'] : array();
+$num = isset($_POST['num']) ? $_POST['num'] : array();
+$price = isset($_POST['price']) ? $_POST['price'] : array();
+$note = isset($_POST['note']) ? htmlspecialcharsFix($_POST['note']) : '';
+$tips = isset($_POST['tips']) ? htmlspecialcharsFix($_POST['tips']) : '';
+$keys = isset($_POST['keys']) ? $_POST['keys'] : '';
+$page = isset($_POST['page']) ? $_POST['page'] : 1;
+
+// Redirect URL
+$redirect_url = "products.php?Keys=" . $keys . "&Page=" . $page;
+if ($category_id) {
+    $redirect_url .= "&category_id=" . $category_id;
+}
+
+// Determine if this is an edit or a new record
+$is_edit = (!empty($id) && is_numeric($id));
+
+// Process nosale array into comma-separated string
+$nosale_str = '';
+if (is_array($nosale) && !empty($nosale)) {
+    $nosale_clean = array_map('intval', $nosale); // Ensure all values are integers
+    $nosale_str = implode(',', $nosale_clean);
+}
+
+// Validate form data (add your validation here)
+if (empty($product_name)) {
+    // You could add error handling here
+    header("Location: " . $redirect_url);
+    exit();
+}
+
+if ($is_edit) {
+    // Update existing product
+    $sql = "UPDATE products SET 
+            ProductName = '" . mysqli_real_escape_string($conn, $product_name) . "',
+            ProductImg = '" . mysqli_real_escape_string($conn, $product_img) . "',
+            Addtime = NOW(),
+            moq = '" . mysqli_real_escape_string($conn, $moq) . "',
+            unit = '" . mysqli_real_escape_string($conn, $unit) . "',
+            nosale = '" . $nosale_str . "',
+            note = '" . mysqli_real_escape_string($conn, $note) . "',
+            tips = '" . mysqli_real_escape_string($conn, $tips) . "',
+            category_id = " . $category_id . "
+            WHERE id = " . (int)$id;
+    mysqli_query($conn, $sql);
+    
+    // Handle price updates
+    mysqli_query($conn, "DELETE FROM price WHERE productId = " . (int)$id . " AND AreaId = 0");
+    
+    if (is_array($num) && is_array($price)) {
+        foreach ($num as $key => $num_value) {
+            if (isset($price[$key])) { // Only process if we have both num and price
+                $num_value = empty($num_value) ? 0 : (float)$num_value;
+                $price_value = empty($price[$key]) ? 0 : (float)$price[$key];
+                $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES 
+                        (" . (int)$id . ", 0, " . $num_value . ", '" . $price_value . "')";
+                mysqli_query($conn, $sql);
+            }
+        }
+    }
+} else {
+    // Insert new product
+    $sql = "INSERT INTO products (ProductName, ProductImg, Addtime, moq, unit, nosale, note, tips, category_id) 
+            VALUES (
+                '" . mysqli_real_escape_string($conn, $product_name) . "',
+                '" . mysqli_real_escape_string($conn, $product_img) . "',
+                NOW(),
+                '" . mysqli_real_escape_string($conn, $moq) . "',
+                '" . mysqli_real_escape_string($conn, $unit) . "',
+                '" . $nosale_str . "',
+                '" . mysqli_real_escape_string($conn, $note) . "',
+                '" . mysqli_real_escape_string($conn, $tips) . "',
+                " . $category_id . "
+            )";
+    mysqli_query($conn, $sql);
+    $id = mysqli_insert_id($conn);
+    
+    // Handle price insertions
+    if (is_array($num) && is_array($price)) {
+        foreach ($num as $key => $num_value) {
+            if (isset($price[$key])) { // Only process if we have both num and price
+                $num_value = empty($num_value) ? 0 : (float)$num_value;
+                $price_value = empty($price[$key]) ? 0 : (float)$price[$key];
+                $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES 
+                        (" . (int)$id . ", 0, " . $num_value . ", '" . $price_value . "')";
+                mysqli_query($conn, $sql);
+            }
+        }
+    }
+}
+
+// Redirect after save
+mysqli_close($conn);
+header("Location: " . $redirect_url);
+exit();