-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
181 lines (156 loc) · 5.85 KB
/
edit.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?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';
function test_inputs($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST['delete'])){
$id = $_POST['id'];
$query = "DELETE from $defaultName where id= $id";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Delete query failed" . mysqli_error($connection));
}
}
if(isset($_POST['table'])){
$nameOfTable = test_inputs($_POST['nameOfTable']);
$query = "CREATE TABLE `$nameOfTable` (
`id` int NOT NULL AUTO_INCREMENT,
`exercise` varchar(100) NOT NULL,
`sets` int NOT NULL,
`repetitions` int NOT NULL,
`weight` int NOT NULL,
`musclegroup` varchar(50) NOT NULL,
`rir` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci";
$result = mysqli_query($connection, $query);
}
if(isset($_POST['submit'])){
$tablename = $_POST['tablename'];
$exercise = test_inputs($_POST['exercise']);
$sets = $_POST['sets'];
$reps = $_POST['repetitions'];
$weight = $_POST['weight'];
$musclegroup = $_POST['musclegroup'];
$rir = $_POST['rir'];
$id = $_POST['id'];
$query = "UPDATE `$tablename` SET exercise='$exercise', sets=$sets, repetitions=$reps, weight=$weight, musclegroup='$musclegroup', rir=$rir WHERE id=$id";
$result = mysqli_query($connection, $query);
// $query = "INSERT INTO todos(task,date) VALUES('$task','$date')";
// $query = "INSERT into $tablename values(null, '$exercise', $sets, $reps, $weight, '$musclegroup', $rir)";
// $result = mysqli_query($connection, $query);
if(!$result){
die("Could not post. Sorry.");
}
}
?>
<!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>
<main class="editProgram">
<div class="create__container">
<h3>Choose Program</h3>
<form action="edit.php" action="GET">
<div class="editProgram__select">
<select 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>
</div>
</form>
<h3>Edit Program</h3>
<?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="editProgram__entry" action="edit.php?tablename=<?=$_GET['tablename']?>" method="POST">
<input class="hideMe" type="text" name="tablename" value=<?=$_GET['tablename']?>>
<select name="id" class="hideMe">
<option value="<?=$id?>"><?=$id?></option>
</select>
<div class="separator">
<label for="exercise">Exercise</label>
<input type="text" name="exercise" id="exercise" value="<?=$exercise ?>" required>
</div>
<div class="separator">
<label for="sets">Sets</label>
<input type="number" name="sets" id="sets" value=<?=$sets?> required>
</div>
<div class="separator">
<label for="reps">Reps</label>
<input type="number" name="repetitions" id="reps" value=<?=$repetitions?> required>
</div>
<div class="separator">
<label for="weight">Weight</label>
<input type="number" name="weight" id="weight" value=<?=$weight?> required>
</div>
<div class="separator">
<label for="musclegroup">Muscle group</label>
<select type="text" name="musclegroup" id="musclegroup" required>
<option value="<?=$musclegroup ?>"><?=$musclegroup?></option>
<option value="Upper Body">Upper Body</option>
<option value="Lower Body">Lower Body</option>
</select>
</div>
<div class="separator">
<label for="rir">RIR</label>
<input type="number" name="rir" id="rir" value=<?= $rir ?>>
</div>
<div class="createProgram__btn">
<button name="submit">Submit</button>
<button name="delete">Delete</button>
</div>
</form>
<?php
};
?>
</div>
</main>
<?php
include './footer.php';
?>
</body>
</html>