/
addingproduct.php
62 lines (52 loc) · 1.89 KB
/
addingproduct.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
<?php
session_start();
$user=$_SESSION['login_user_id'];
$title=$_POST['title'];
$years=$_POST['years'];
$details=$_POST['details'];
$price=$_POST['price'];
$category=0;
$category=$_POST['category'];
include_once("connect_to_mysql.php");
$sql=mysqli_query($conn,"SELECT * from products");
$productCount=mysqli_num_rows($sql);
$productCount=$productCount+1;
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'];
// echo end();
$t=explode('.',$_FILES['image']['name']);
$t=end($t);
$file_ext=strtolower($t);
$expensions= array("jpg","jpeg","png","jpe");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"images/store_images/".$productCount.".jpg");
echo "Success";
}
else{
print_r($errors);
}
}
date_default_timezone_set('Asia/Calcutta');
$datetime =new datetime(date('Y/m/d H:i:s'));
$datetime->modify('+1 day');
$enddate=$datetime->format('Y-m-d H:i:s');
$sq="INSERT INTO products(ProductID,Pname,StartingPrice,SellerID,CategoryID,YearsofUsage,Details) values('".$productCount."','".$title."','".$price."','".$user."','".$category."','".$years."','".$details."')";
$sq2="INSERT INTO auction(ProductID,EndTime,CurrentPrice) values('".$productCount."','".$enddate."','".$price."')";
if ($conn->query($sq) === TRUE && $conn->query($sq2) === TRUE) {
echo "New record created successfully";
header("location: index.php");
} else {
echo "Error: " . $sq . "<br>" . $conn->error;
}
$conn->close();
?>