query($sql);
if ($row = $rs->fetch()) {
$sql = "Update Products Set
ProductName='" . $productName . "',
ProductImg='" . $productImg . "',
Addtime=NOW(),
moq='" . $moq . "',
unit='" . $unit . "',
nosale='" . $nosale . "',
note='" . $note . "',
tips='" . $tips . "'
Where id=" . $id;
$conn->query($sql);
$conn->query("delete from price where productId=" . $id . " and AreaId=0");
$numarr = explode(",", $num);
$pricearr = explode(",", $price);
for ($i = 0; $i < count($numarr); $i++) {
if ($numarr[$i] == "") $numarr[$i] = 0;
if ($pricearr[$i] == "") $pricearr[$i] = 0;
$conn->query("insert into price (productId,AreaId,num,price) values(" . $id . ",0," . $numarr[$i] . ",'" . $pricearr[$i] . "')");
}
}
} else {
$sql = "Insert Into Products(ProductName,ProductImg,Addtime,unit,moq,nosale,note,tips) values(
'" . $productName . "',
'" . $productImg . "',
NOW(),
'" . $unit . "',
'" . $moq . "',
'" . $nosale . "',
'" . $note . "',
'" . $tips . "'
)";
$conn->query($sql);
$sql = "select top 1 id from Products order by id desc";
$rs = $conn->query($sql);
$id = $rs->fetch()['id'];
$numarr = explode(",", $num);
$pricearr = explode(",", $price);
for ($i = 0; $i < count($numarr); $i++) {
if ($numarr[$i] == "") $numarr[$i] = 0;
if ($pricearr[$i] == "") $pricearr[$i] = 0;
$conn->query("insert into price (productId,AreaId,num,price) values(" . $id . ",0," . $numarr[$i] . ",'" . $pricearr[$i] . "')");
}
}
$page = $_GET['Page'] ?? '';
$keys = urlencode($_GET['Keys'] ?? '');
header("Location: ?keys=" . $keys . "&Page=" . $page . $urlStr);
exit;
}
if ($act == "add" || $act == "edit") {
$id = $_GET['id'] ?? '';
$isedit = false;
if ($id != "" && is_numeric($id)) {
$isedit = true;
$sql = "Select ProductName,ProductImg,unit,moq,nosale,note,tips from Products Where id=" . $id;
$rs = $conn->query($sql);
if ($row = $rs->fetch()) {
$productName = textUncode($row['ProductName']);
$productImg = textUncode($row['ProductImg']);
$unit = $row['unit'];
$moq = textUncode($row['moq']);
$nosale = $row['nosale'];
$note = textUncode($row['note']);
$tips = textUncode($row['tips']);
} else {
$isedit = false;
}
}
$page = $_GET['Page'] ?? '';
$keys = urlencode($_GET['Keys'] ?? '');
$hrefstr = "?keys=" . $keys . "&Page=" . $page;
?>
query($sqlStr);
}
header("Location: ?Keys=" . $keys . "&Page=" . $page);
exit;
}
// 主列表页面
$keyscode = textEncode($_GET['Keys'] ?? '');
$page = $_GET['Page'] ?? '';
$sqlStr = "Select id,ProductName,ProductImg from Products order by id Desc";
$rs = $conn->query($sqlStr);
?>