-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditTime.php
62 lines (56 loc) · 1.93 KB
/
editTime.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
<?php
require_once 'connect.php';
require_once 'functions.php';
$pageTitle = "Edit Time";
if (isLoggedIn()) {
} else {
header('Location: index.php');
die();
}
if(isset($_POST['timeID']) && !empty($_POST['timeID'])) {
$id = $_POST['timeID'];
$query = "SELECT * FROM time_entries WHERE id=".$id;
if ($result = mysqli_query($connect, $query)) {
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
}
}
if(isset($_POST['timeIn']) && isset($_POST['timeOut'])) {
if (!empty($_POST['timeIn']) && !empty($_POST['timeOut'])) {
if ($_POST['timeOut'] <= $_POST['timeIn']) {
header('Location:index.php?msg=5');
die();
}
$query2 = "UPDATE time_entries SET timeIn = '".strtotime($_POST['timeIn'])."', timeOut = '".strtotime($_POST['timeOut'])."', comments='".$_POST['comments']."' WHERE id=".$_POST['id'];
if ($result2 = mysqli_query($connect, $query2)) {
header('Location:index.php?msg=3');
}
else {
header('Location:index.php?msg=4');
}
}
}
include 'header.php';
?>
<h2>Edit Time Entry</h2>
<hr>
<strong>Current Values:</strong><br>
<?php
echo "Time in: ".date('D, M j, Y, g:i a', $row['timeIn'])."<br>";
echo "Time out: ".date('D, M j, Y, g:i a', $row['timeOut']);
?>
<br><br>
<form action="editTime.php" method="POST">
<strong>Modify Values:</strong><br>
<label>Time in: </label><input type="datetime-local" name="timeIn" value="<?php echo date('Y-m-d\TH:i', $row['timeIn']); ?>"/><br><br>
<label>Time out: </label><input type="datetime-local" name="timeOut" value="<?php echo date('Y-m-d\TH:i', $row['timeOut']); ?>"/><br>
<input type="hidden" name="id" value="<?php echo $id; ?>"/><br>
Comments:<br><textarea id="comments" name="comments" class="comments" placeholder="Please provide a brief comment as to why you edited this entry." maxlength="150" required>
<?php if (isset($row['comments'])) { echo sanitize($row['comments']); }?>
</textarea><br>
<p>
<input type="submit" value="Update" />
</p>
</form>
<?php
include 'footer.php';
?>