-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct_doInsert.php
More file actions
35 lines (27 loc) · 1.21 KB
/
Copy pathproduct_doInsert.php
File metadata and controls
35 lines (27 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once ("pdo-connect.php");
$name=$_POST["name"];
$price=$_POST["price"];
$description=$_POST["description"];
//$valid=$_POST["valid"];
$brand_category=$_POST["brand_category"];
$product_category=$_POST["product_category"];
$pet_category=$_POST["pet_category"];
$stock_num=$_POST["stock_num"];
$now=date("Y-m-d H:i:s");
$img=$_POST["img"];
//$sql = "INSERT INTO products (name, price, description, brand_category, product_category, pet_category, stock_num, img, created_at) VALUES ('$name', '$price', '$description', '$brand_category', '$product_category', '$pet_category', '$stock_num', '$img', '$now')";
$sql="INSERT INTO products (name, price, description, brand_category, product_category, pet_category, stock_num, img, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt=$db_host->prepare($sql);
try{
$stmt->execute([$name, $price, $description, $brand_category, $product_category, $pet_category, $stock_num, $img, $now]);
header("location: product_manage.php");
}catch(PDOException $e){
echo $e->getMessage();
}
//if ($db_host->exec($sql) === TRUE) {
// echo "新增資料完成<br>";
// header("location: product_manage.php");
//} else {
// echo "新增資料錯誤: " . $conn->error;
//}