-
Notifications
You must be signed in to change notification settings - Fork 0
/
addproduct.php
128 lines (123 loc) · 5.29 KB
/
addproduct.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php include 'header.php'; ?>
<script type="text/javascript">
$(document).ready(function() {
$('select').material_select();
});
</script>
<div class="container">
<form class="" action="#" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col s12">
<h3 class="center">เพิ่มสินค้า</h3>
</div>
</div>
<div class="row">
<div class="col s6 center-align">
<!-- <div class="col s6 input-field">
<input name="Product_ID" type="text" class="validate" required>
<label for="รหัสสินค้า">รหัสสินค้า</label>
</div> -->
<div class="col s12 input-field">
<input name="Product_Name" type="text" class="validate" required>
<label for="ชื่อสินค้า">ชื่อสินค้า</label>
</div>
<div class="col s6 input-field">
<input name="Product_Price" type="number" class="validate" step="0.01" required>
<label for="ราคาสินค้า">ราคาสินค้า</label>
</div>
<div class="col s6 input-field">
<input name="Product_QTY" type="number" class="validate" required>
<label for="จำนวนสินค้า">จำนวนสินค้า</label>
</div>
<div class="col s12 input-field">
<textarea name="Product_Title" class="materialize-textarea"></textarea>
<label for="Title สินค้า">Title สินค้า</label>
</div>
<div class="col s12 input-field">
<textarea name="Product_Detail" class="materialize-textarea"></textarea>
<label for="รายละเอียดสินค้า">รายละเอียดสินค้า</label>
</div>
<div class="col s6 input-field">
<select name="Type_ID" required>
<option value="" disabled selected>เลือกประเภทสินค้า</option>
<?php
$sql = "SELECT * FROM type";
$result = $connect->query($sql);
while ($row = $result->fetch_array()) {
?>
<option value="<?php echo $row['Type_ID']; ?>"><?php echo $row['Type_Name']; ?></option>
<?php
}
?>
</select>
<label>เลือกประเภทสินค้า</label><br>
</div>
<div class="col s6 input-field">
<select name="Band_ID" required>
<option value="" disabled selected>เลือกแบรนสินค้า</option>
<?php
$sql = "SELECT * FROM band";
$result = $connect->query($sql);
while ($row = $result->fetch_array()) {
?>
<option value="<?php echo $row['Band_ID']; ?>"><?php echo $row['Band_Name']; ?></option>
<?php
}
?>
</select>
<label>เลือกแบรนสินค้า</label><br>
</div>
</div>
<div class="col s6 center-align">
<div class="col s12">
<div class="img"> <img id="output"/ width=500px height=400px> </div>
<br>
</div>
<div class="col s12">
<input type="file" name="fileToUpload" accept="product/*" onchange="loadFile(event)">
<script>
var loadFile = function(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
};
</script>
</div>
</div>
</div>
<div class="row">
<div class="col s6 right-align">
<button class="btn waves-effect waves-light #01579b light-blue darken-4 z-depth-4" type="submit" name="action">เพิ่มสินค้า
<i class="material-icons right">send</i>
</button>
</div>
<div class="col s6 left-align">
<button class="btn waves-effect waves-light #b71c1c red darken-4 z-depth-4" type="reset" name="action">Reset
<i class="material-icons right">settings_backup_restore</i>
</button>
</div>
</div>
</form>
</div>
<?php include 'footer.php'; ?>
<?php
if($_POST){
// $Product_ID = $_POST['Product_ID'];
$Product_Name = $_POST['Product_Name'];
$Product_Price = $_POST['Product_Price'];
$Product_QTY = $_POST['Product_QTY'];
$Product_Title = $_POST['Product_Title'];
$Product_Detail = $_POST['Product_Detail'];
$Type_ID = $_POST['Type_ID'];
$Band_ID = $_POST['Band_ID'];
$target_dir = "product/";
$insert_picture = "product/";
$target_file = $target_dir.$_FILES["fileToUpload"]["name"];
$insert_picture = $insert_picture.$_FILES['fileToUpload']['name'];
if(copy($_FILES['fileToUpload']['tmp_name'], $target_file)){
echo "Add Complete";
}
$sql = "INSERT INTO product (Product_Name,Product_Price,Product_QTY,Product_Title,Product_Detail,Product_IMG,Type_ID,Band_ID)
VALUES ('$Product_Name','$Product_Price','$Product_QTY','$Product_Title','$Product_Detail','$insert_picture','$Type_ID','$Band_ID');";
$connect->query($sql);
}
?>