-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddPost.php
49 lines (37 loc) · 1.33 KB
/
AddPost.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
<?php
$con = mysqli_connect("localhost", "root", "WhatHappendPWD.", "whathappend");
if(mysqli_connect_error()){
echo "failed to connect".mysqli_connect_error();
}
if (!empty($_POST)) {
$post = "";
$long = "";
$lat = "";
if (empty($_POST['post']) || empty($_POST['longitude']) || empty($_POST['latitude']) || empty($_POST['range'])) {
$response["success"] = 0;
$response["message"] = "Post, location or range was empty.";
die(json_encode($response));
} else{
$post = $_POST['post'];
$user = $_POST['user'];
$long = $_POST['longitude'];
$lat = $_POST['latitude'];
$range = $_POST['range'];
//$timestamp = $_POST['timestamp'];
}
$query="INSERT INTO posts (`post`, `user`, `long`, `lat`, `range`, `timestamp`) VALUES (\"".$post."\", \"".$user."\", \"".$long."\", \"".$lat."\", \"".$range."\", now())";
//$query="INSERT INTO posts (post, user, long, lat, range, timestamp) VALUES (\"".$post."\", \"".$user."\", \"".$long."\", \"".$lat."\", \"".$range."\", \"".$timestamp."\")";
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);
?>