-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkin.php
53 lines (41 loc) · 1.53 KB
/
checkin.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
<?php
$server = "localhost";
$username = "bounce";
$password = "wesbounce";
$database = "bounce";
$connection = mysql_connect($server, $username, $password) or die
("Could not connect: " . mysql_error());
mysql_select_db($database, $connection);
$userid = $_POST["userid"];
$location = mysql_real_escape_string($_POST["location"]);
$sql = "SELECT pid FROM users WHERE fid=" . $userid . ";";
$result = mysql_query($sql, $connection) or die (mysql_error());
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_assoc($result);
$sql = "UPDATE parties SET attendees=attendees-1 WHERE ";
$sql .= "pid='" . $result["pid"] . "';";
$result = mysql_query($sql, $connection) or die (mysql_error());
$sql = "DELETE FROM parties WHERE attendees=0;";
$result = mysql_query($sql, $connection) or die (mysql_error());
}
$sql = "INSERT INTO parties (location, attendees) ";
$sql .= "VALUES ('" . $location . "', 1)";
$sql .= "ON DUPLICATE KEY UPDATE attendees=attendees+1;";
if (!mysql_query($sql, $connection)) {
die('Error: ' . mysql_error());
} else {
}
$sql = "SELECT pid FROM parties WHERE location='" . $location . "';";
$result = mysql_query($sql, $connection) or die (mysql_error());
$pid = mysql_fetch_assoc($result);
$pid = $pid["pid"];
$sql = "INSERT INTO users (fid, pid) VALUES ";
$sql .= "('" . $userid . "', " . $pid . ")";
$sql .= "ON DUPLICATE KEY UPDATE pid=" . $pid . ";";
if (!mysql_query($sql, $connection)) {
die('Error: ' . mysql_error());
} else {
echo "Location updated!";
}
mysql_close($connection);
?>