-
Notifications
You must be signed in to change notification settings - Fork 2
/
addItems.php
60 lines (35 loc) · 1.44 KB
/
addItems.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
<?php
session_start();
$user_id = $_SESSION['user_id'];
$conn = mysqli_connect('localhost','jwu','love.09221213','ou_ecommerce');
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"image/".$file_name);
}else{
print_r($errors);
}
}
$product_name = $_POST['product_name'];
$product_brand = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_quantity = $_POST['product_quantity'];
$product_image = $file_name;
$sql = "INSERT INTO `product`(`seller_id`, `product_name`, `product_brand`, `product_price`,`product_image`, `product_quantity`,`product_status`) VALUES ('$user_id','$product_name','$product_brand','$product_price','$product_image','$product_quantity','1')";
$query = mysqli_query($conn,$sql);
if($query){
header('Location: viewProducts.php');
}
?>