-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackupAddPost.php
46 lines (32 loc) · 979 Bytes
/
BackupAddPost.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
<?php
$con = mysqli_connect("localhost", "root", "WhatHappendPWD.", "whathappend");
if(mysqli_connect_error()){
echo "failed to connect".mysqli_connect_error();
}
if (!empty($_POST)) {
$post = "";
$location = "";
if (empty($_POST['post']) || empty($_POST['location'])) {
$response["success"] = 0;
$response["message"] = "Post or timestamp was empty.";
die(json_encode($response));
} else{
$post = $_POST['post'];
$location = $_POST['location'];
$user = $_POST['user'];
}
$query="INSERT INTO posts (post, user, location, timestamp) VALUES (\"".$post."\", \"".$user."\", \"".$location."\", now())";
if (!mysqli_query($con,$query)) {
$response["success"] = 0;
$response["message"] = "Problem with adding your post. Please try again.";
die(json_encode($response));
}
else{
$response["success"] = 1;
$response["message"] = "Everything looks fine.";
die(json_encode($response));
}
}
//Disconnect from the server
mysqli_close($con);
?>