-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhitdice.php
64 lines (55 loc) · 2.54 KB
/
hitdice.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
55
56
57
58
59
60
61
62
63
64
<?php
include "db_connect.php";
if (isset($_POST['relationship'])): {
$relationship = mysqli_escape_string($conn, $_POST['relationship']);
$hitdiespent = mysqli_escape_string($conn, $_POST['hitdiespent']);
$sql = "SELECT * FROM `character-classes` WHERE `character-class-id` LIKE ?";
if ($stmt = mysqli_prepare($conn, $sql)): {
mysqli_stmt_bind_param($stmt, "i", $relationship);
mysqli_stmt_execute($stmt);
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$currenthitdie = $row['hitdice'];
if ($hitdiespent == 1): {
$newhitdie = $currenthitdie - 1;
$sql = "UPDATE `character-classes` SET `hitdice`=? WHERE `character-class-id` LIKE ?";
if ($stmt = mysqli_prepare($conn, $sql)): {
mysqli_stmt_bind_param($stmt, "ii", $newhitdie, $relationship);
mysqli_stmt_execute($stmt);
} endif;
} else: {
$newhitdie = $currenthitdie + 1;
$sql = "UPDATE `character-classes` SET `hitdice`=? WHERE `character-class-id` LIKE ?";
if ($stmt = mysqli_prepare($conn, $sql)): {
mysqli_stmt_bind_param($stmt, "ii", $newhitdie, $relationship);
mysqli_stmt_execute($stmt);
} endif;
} endif;
} endif;
} elseif (isset($_POST['characterid'])): {
$characterid = mysqli_escape_string($conn, $_POST['characterid']);
$sql = "SELECT * FROM `character-classes` WHERE `character-id` LIKE ?";
if ($stmt = mysqli_prepare($conn, $sql)): {
mysqli_stmt_bind_param($stmt, "i", $characterid);
$stmt->execute();
$result = $stmt->get_result();
$classes = $result->fetch_all(MYSQLI_ASSOC);
for ($i = 0; $i < count($classes); $i++) {
$relationship = $classes[$i]['character-class-id'];
$level = $classes[$i]['levels'];
$currenthitdice = $classes[$i]['hitdice'];
$resthitdie = floor($level / 2);
if (($currenthitdice + $resthitdie) > $level): {
$newhitdie = $level;
} else: {
$newhitdie = $currenthitdice + $resthitdie;
} endif;
$sql = "UPDATE `character-classes` SET `hitdice`= ? WHERE `character-class-id` LIKE ?";
if ($stmt = mysqli_prepare($conn, $sql)): {
mysqli_stmt_bind_param($stmt, "ii", $newhitdie, $relationship);
mysqli_stmt_execute($stmt);
} endif;
}
} endif;
} endif;
?>