-
Notifications
You must be signed in to change notification settings - Fork 0
/
purchase.php
39 lines (29 loc) · 1.26 KB
/
purchase.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
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname); // Create connection
if ($conn->connect_error) { // Check connection
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST['name'];
$days = $_POST['days'];
$sql = "SELECT * FROM users WHERE name='" . $name . "'";
$result = @mysqli_query($conn, $sql);
$fetch = mysqli_fetch_assoc($result);
$odate = $fetch["untill"];
$odatetime = strtotime($odate);
if (mysqli_num_rows($result) >= 1 and $odatetime > time()) {
$newdate = date('Y-m-d H:i:s', strtotime($odate . ' + ' . $days . ' days'));
$sql = "UPDATE users SET untill = '" . $newdate . "' WHERE name = '" . $name . "'";
$result = @mysqli_query($conn, $sql);
} elseif (mysqli_num_rows($result) >= 1 and $odatetime <= time()) {
$date = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s', time()) . '+ ' . $days . ' days'));
$sql = "UPDATE users SET untill = '" . $date . "' WHERE name = '" . $name . "'";
$result = @mysqli_query($conn, $sql);
} else {
$date = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s', time()) . '+ ' . $days . ' days'));
$sql = "INSERT INTO users (name, untill) VALUES('" . $name . "', '" . $date . "')";
$result = @mysqli_query($conn, $sql);
}