-
Notifications
You must be signed in to change notification settings - Fork 1
/
addLocationProcess.php
47 lines (38 loc) · 1.78 KB
/
addLocationProcess.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
<?php
include 'includes/session.php';
include 'includes/dbConnect.php';
if (isset($_POST['add'])){
$meeting_id = mysqli_real_escape_string($connection, $_GET['meeting_id']);
$latitude = mysqli_real_escape_string($connection, $_POST['latitude']);
$longitude = mysqli_real_escape_string($connection, $_POST['longitude']);
$location = mysqli_real_escape_string($connection, $_POST['location']);
$query = "SELECT location_id FROM locations WHERE name='$location'";
$result = mysqli_query($connection, $query);
$numResult = mysqli_num_rows($result);
if ($numResult){
$place = mysqli_fetch_array($result, MYSQLI_ASSOC);
$location_id = $place['location_id'];
}
else {
$query = "INSERT INTO locations (name, latitude, longitude) VALUES ('$location', '$latitude', '$longitude')";
$result = mysqli_query($connection, $query);
$query = "SELECT location_id FROM locations WHERE name='$location'";
$result = mysqli_query($connection, $query);
$place = mysqli_fetch_array($result, MYSQLI_ASSOC);
$location_id = $place['location_id'];
}
$query = "SELECT * FROM meeting_locations WHERE meeting_id='$meeting_id' && location_id='$location_id'";
$result = mysqli_query($connection, $query);
$numResult = mysqli_num_rows($result);
if (!$numResult){
$query = "INSERT INTO meeting_locations (meeting_id, location_id, proposed_user_id) VALUES ('$meeting_id', '$location_id', '$user_id')";
$result = mysqli_query($connection, $query);
$query = "UPDATE meeting_users SET user_location_id='$location_id' WHERE meeting_id='$meeting_id' && user_id='$user_id'";
$result = mysqli_query($connection, $query);
header("Location: meeting.php?meeting_id=$meeting_id");
}
else {
echo 'The location you specified has already been proposed.';
}
}
?>