-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
140 lines (114 loc) · 3.99 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
include './sessions.php';
require_login($loginCheck);
include './db.php';
$cookieTable = $_GET['tablename'] ?? 'workouts';
setcookie('tablename',$cookieTable,time() + 86400 * 3, "/");
$defaultName = $_GET['tablename'] ?? $_COOKIE['tablename'] ?? 'workouts';
if (isset($_POST['addOne'])){
$id= $_POST['id'];
$weight = $_POST['weight'];
$query = "UPDATE {$_GET['tablename']} SET weight=$weight+1 where id = $id";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Update query failed" . mysqli_error($connection));
}
};
if (isset($_POST['addFive'])){
$id= $_POST['id'];
$weight = $_POST['weight'];
$query = "UPDATE {$_GET['tablename']} SET weight=$weight+5 where id = $id";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Update query failed" . mysqli_error($connection));
}
};
if (isset($_POST['addTen'])){
$id= $_POST['id'];
$weight = $_POST['weight'];
$query = "UPDATE {$_GET['tablename']} SET weight=$weight+10 where id = $id";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Update query failed" . mysqli_error($connection));
}
};
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="./weightlogo.svg" type="image/x-icon"/>
<link rel="stylesheet" href="index.css">
<title>Reps</title>
</head>
<body>
<header>
<?php
include './nav.php';
?>
</header>
<section class="exercises">
<form action="index.php" action="GET">
<select class="selectProgram" name="tablename">
<?php $query = "SHOW TABLES";
$result = mysqli_query($connection, $query);
if(!$result){
die('No exercises to get');
};
while($row = mysqli_fetch_assoc($result)){
$tablesin = $row['Tables_in_gym'];
?>
<option value="<?= $tablesin ?>"><?=$tablesin?></option>
<?php
} ?>
<option value="<?=$defaultName?>" selected disabled><?=$defaultName?></option>
</select>
<button>Submit</button>
</form>
<div class="entries">
<?php
$query = "SELECT * from {$defaultName}";
$result = mysqli_query($connection, $query);
if(!$result){
die('No exercises to get');
};
while($row = mysqli_fetch_assoc($result)){
$id = $row['id'];
$exercise = $row['exercise'];
$sets = $row['sets'];
$repetitions = $row['repetitions'];
$weight = $row['weight'];
$musclegroup = $row['musclegroup'];
$rir = $row['rir'];
?>
<form class="entry" action="index.php?tablename=<?=$defaultName?>" method="POST" >
<p class="hideMe"><select name="id" >
<option value="<?=$id?>"><?=$id?></option>
</select> <input name="weight" value="<?= $weight?>"/></p>
<p class="entry__text"> <?= $exercise .' '. $sets ."x". $repetitions .' '. $weight ."Kg"?> </p>
<div class="entry__buttons">
<button class="addButton" name="addOne">+1</button>
<button class="addButton" name="addFive">+5</button>
<button class="addButton" name="addTen">+10</button>
</div>
</form>
<?php
};
?>
</div>
</section>
<?php
include './footer.php';
?>
<script>
const entries = document.querySelectorAll('.entry');
entries.forEach(entry =>{
entry.addEventListener('click', () =>{
entry.classList.toggle('completed');
})
})
</script>
</body>
</html>