-
Notifications
You must be signed in to change notification settings - Fork 3
/
add_item_to_database.php
102 lines (82 loc) · 3.1 KB
/
add_item_to_database.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
<?php
date_default_timezone_set("Asia/Dhaka");
$product_name = $_POST['pname'];
$seller_id = $_POST['sid'];
$initial_bid = $_POST['ini_bid'];
$category = $_POST['category'];
$location = $_POST['location'];
$bid_s_time = $_POST['starttime'];
$bid_e_time = $_POST['endtime'];
$description = $_POST['description'];
/*echo "product_name is : $product_name"."<br>";
echo "seller_id is : $seller_id"."<br>";
echo "initial_bid is : $initial_bid"."<br>";
echo "category is : $category"."<br>";
echo "location is : $location"."<br>";
echo "bid_s_time is : $bid_s_time"."<br>";
echo "bid_e_time is : $bid_e_time"."<br>";
echo "description : $description"."<br>";*/
$user = "root";
$pass = "";
$db = "online_auction_system";
$db_connect = mysqli_connect("localhost", $user, $pass, $db) or die("no database found");
echo "database connected";
$time_trackID = mysqli_num_rows(mysqli_query($db_connect, "SELECT * FROM time_track")) + 1;
echo "$time_trackID"."<br>";
$qry = "INSERT INTO time_track VALUES ('$time_trackID', '$bid_s_time', '$bid_e_time')";
$qry_exec = mysqli_query($db_connect, $qry);
$qry = "SELECT ID FROM locations WHERE Name = '$location'";
$qry_exec = mysqli_query($db_connect, $qry);
$row = mysqli_fetch_assoc($qry_exec);
$location_id = $row['ID'];
$product_id = mysqli_num_rows(mysqli_query($db_connect, "SELECT * FROM product")) + 1;
echo "$product_id"."<br>";
$qry = "INSERT INTO product VALUES ('$product_id', '$product_name', '$category', '$initial_bid', '$description', '$seller_id', '$location_id', '$time_trackID', '1')";
$qry_exec = mysqli_query($db_connect, $qry);
$bid_id = mysqli_num_rows(mysqli_query($db_connect, "SELECT * FROM bid")) + 1;
/*if($bid_e_time < date("h:i:s"))
{
$status = "yet to bid";
}
else if($bid_s_time <= date("h:i:s") && $bid_e_time >= date("h:i:s"))
{
$status = "ongoing";
}
else if($bid_s_time > date("h:i:s"))
{
$status = "finished";
}*/
/*$date = date('Y-m-d h:i', time());
list($dat, $tm) = explode('T', $bid_s_time);
$bid_s_time = $dat." ".$tm;
$timestamp = new DateTime($bid_s_time);
$timestamp = $timestamp->getTimestamp();
echo "$dat "."$tm "."$bid_s_time "."$timestamp"."<br><br>";
//$date = strftime('%Y-%m-%dT%H:%M', strtotime($bid_s_time));
echo "$bid_s_time"." "."$bid_e_time "."$date"."<br>";*/
$nt = new DateTime($bid_s_time);
$bid_s_time = $nt->getTimestamp();
$nt = new DateTime($bid_e_time);
$bid_e_time = $nt->getTimestamp();
$date = time();
echo "$bid_s_time"." "."$bid_e_time "."$date"."<br>";
if($bid_s_time > $date)
{
$status = "yet to bid";
}
else if($bid_s_time <= $date && $bid_e_time >= $date)
{
$status = "ongoing";
}
else if($bid_e_time < $date)
{
$status = "finished";
}
$qry1 = "INSERT INTO bid VALUES ('$bid_id', '$status', '$initial_bid', '$seller_id', '$product_id', '$seller_id', '$time_trackID')";
$qry_exec1 = mysqli_query($db_connect, $qry1);
if($qry_exec && $qry_exec1)
{
echo "Successfylly added";
header("Location: startpage.php");
}
?>