-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_favoriteEx.php
68 lines (51 loc) · 2.15 KB
/
product_favoriteEx.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
<?php
include "db_conn.php";
if (isset($_POST['product']) && isset($_POST['seller']) && isset($_POST['user']) && isset($_POST['condition'])) {
$product = $_POST["product"];
$seller = $_POST["seller"];
$user = $_POST["user"];
$condition = $_POST["condition"];
if ($condition === "true") {
$sql1 = "SELECT * FROM `product_favorite` WHERE `product` = '$product' AND `seller` = '$seller' AND `user` = '$user'";
$result1 = mysqli_query($conn, $sql1);
if ($result1 && mysqli_num_rows($result1) > 0) {
date_default_timezone_set('Asia/Manila');
$currentDateTime = date('Y-m-d H:i:s');
$date = date('Y-m-d', strtotime($currentDateTime));
$time = date('H:i:s', strtotime($currentDateTime));
$sql2 = "DELETE FROM `product_favorite` WHERE `product` = '$product' AND `seller` = '$seller' AND `user` = '$user'";
$result2 = mysqli_query($conn, $sql2);
if ($result2){
echo "T_Success";
} else {
echo "T_Failed";
}
} else {
echo "Existing";
}
} else if ($condition === "false") {
$sql1 = "SELECT * FROM `product_favorite` WHERE `product` = '$product' AND `seller` = '$seller' AND `user` = '$user'";
$result1 = mysqli_query($conn, $sql1);
if ($result1 && mysqli_num_rows($result1) > 0) {
echo "Existing";
} else {
date_default_timezone_set('Asia/Manila');
$currentDateTime = date('Y-m-d H:i:s');
$date = date('Y-m-d', strtotime($currentDateTime));
$time = date('H:i:s', strtotime($currentDateTime));
$sql2 = "INSERT INTO `product_favorite`(`product`, `user`, `seller`, `date`, `time`)
VALUES ('$product','$user','$seller','$date','$time')";
$result2 = mysqli_query($conn, $sql2);
if ($result2){
echo "F_Success";
} else {
echo "F_Failed";
}
}
} else {
echo "Condition";
}
} else {
echo "Unknown";
}
?>