-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_group.php
54 lines (54 loc) · 2.05 KB
/
create_group.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
54
<?php
/**
* Created by PhpStorm.
* User: sid
* Date: 9/5/15
* Time: 2:40 AM
*/
session_start();
$servername = "us-cdbr-azure-east-b.cloudapp.net";
$username = "b0e812d8bf4e3e";
$password = "124f7801";
if(!isset($_SESSION['id']) || $_SESSION['loggedin'] === false){
header("Location: login.html");
die();
}
try {
$conn = new PDO("mysql:host=$servername;dbname=complaydb", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$game = $_POST['game'];
//$memberlimit = $_POST['memberlimit'];
$memberlimit = 0;
$locx = $_POST['locx'];
$locy = $_POST['locy'];
$name = $_POST['name'];
$skill = $_POST['skill'];
$skill--;
//$privacy = $_POST['privacy'];
$privacy = "open";
$posters = $_POST['posters'];
$timetoexpire = $_POST['timetoexpire'];
$timetoexpire = $timetoexpire * 3600;
$ownerid = $_SESSION['id'];
$set_id = $conn->prepare("SET @g=LEFT(UUID(), 10)");
$set_id->execute();
$insert_group = $conn->prepare("INSERT INTO groups VALUES (@g, :game, :memberlimit, POINT(:locx, :locy), :groupname, :skill, :privacy, :posters, FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + :timetoexpire), CURRENT_TIMESTAMP(), :ownerid)");
$insert_group->bindParam(":game", $game);
$insert_group->bindParam(":memberlimit", $memberlimit);
$insert_group->bindParam(":locx", $locx);
$insert_group->bindParam(":locy", $locy);
$insert_group->bindParam(":groupname", $name);
$insert_group->bindParam(":skill", $skill);
$insert_group->bindParam(":privacy", $privacy);
$insert_group->bindParam(":posters", $posters);
$insert_group->bindParam(":timetoexpire", $timetoexpire);
$insert_group->bindParam(":ownerid", $ownerid);
$insert_group->execute();
$add_self_to_group = $conn->prepare("INSERT INTO groupmembers VALUES(:ownerid, @g)");
$add_self_to_group->bindParam(":ownerid", $ownerid);
$add_self_to_group->execute();
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>