Commit 179ba302503bd00e872fda9e67009a0e559c5260
1 parent
b58c4ac9
Connect to database and insert values
Showing
1 changed file
with
22 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,22 @@ |
1 | +<?php | |
2 | +$conn = mysqli_connect('localhost', 'mysql_user', 'mysql_passwd', 'IoT'); | |
3 | + | |
4 | +$newTraining= $_POST['newTraining']; | |
5 | +$name = $_POST['name']; | |
6 | +$lapTime = $_POST['lapTime']; | |
7 | +$trainingDate = $_POST['trainingDate']; | |
8 | + | |
9 | +$max = mysqli_query($conn,"SELECT MAX(trainingId) FROM training"); | |
10 | +if($newTraining==1){ | |
11 | + $max+=1; | |
12 | + $lastLap=0; | |
13 | +} | |
14 | +else $lastLap = mysqli_query($conn,"SELECT MAX(lapId) FROM lap WHERE trainingId='$max'"); | |
15 | + | |
16 | +$iduser = mysqli_query($conn, "SELECT id FROM user WHERE name='$name'"); | |
17 | +$result = mysqli_query($conn, "INSERT INTO training (trainingId, trainingDate, userId) VALUES ('$max', '$trainingDate', '$iduser')"); | |
18 | +$result = mysqli_query($conn, "INSERT INTO lap (lapId, lapTime, trainingId) VALUES ('$lastLap', '$lapTime', '$max')"); | |
19 | + | |
20 | +mysqli_close($conn); | |
21 | + | |
22 | +?> | |
0 | 23 | \ No newline at end of file | ... | ... |