-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
71 lines (69 loc) · 2.22 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
<?PHP include 'server.php';
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($db, "SELECT * FROM tasks WHERE id=".$id);
if ( $record ) {
$n = mysqli_fetch_array($record);
$task = $n['task'];
}
}
?>
<!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="stylesheet" type="text/css" href="style.css" />
<title>Document</title>
</head>
<body>
<h2>ToDo List</h2>
<?PHP if (isset($_SESSION['message'])): ?>
<div class="msg">
<?PHP echo $_SESSION['message']; unset($_SESSION['message']); ?>
</div>
<?PHP endif; ?>
<form action="server.php" method="post">
<div class="input-group">
<input type="hidden" name="id" value="<?PHP echo $id ?>" />
</div>
<div class="input-group">
<label for="task">Task</label>
<input type="text" name="task" value="<?PHP echo $task ?>" />
</div>
<div class="input-group">
<?PHP if ($update == true): ?>
<button class="btn" type="submit" name="update">Update</button>
<?PHP else: ?>
<button class="btn" type="submit" name="save">Save</button>
<?PHP endif; ?>
</div>
</form>
<?PHP $results = mysqli_query($db, "SELECT * FROM tasks"); ?>
<table>
<thead>
<tr>
<th>#</th>
<th>Task</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?PHP while($row = mysqli_fetch_array($results)) { ?>
<tbody>
<tr>
<td><?PHP echo $row['id']; ?></td>
<td><?PHP echo $row['task']; ?></td>
<td>
<a href="index.php?edit=<?PHP echo $row['id']; ?>" class="edit_btn">Edit</a>
</td>
<td>
<a href="server.php?del=<?PHP echo $row['id']; ?>" class="del_btn">Delete</a>
</td>
</tr>
<?PHP } ?>
</tbody>
</table>
</body>
</html>