mirror of
https://github.com/bckelley/todo-list.git
synced 2026-08-24 01:14:11 -05:00
initial commit
This commit is contained in:
@@ -0,0 +1,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>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?PHP
|
||||
|
||||
session_start();
|
||||
$db = mysqli_connect('localhost', 'root', 'admin', 'todo');
|
||||
|
||||
$task = "";
|
||||
$id = 0;
|
||||
$update = false;
|
||||
|
||||
if (isset($_POST['save'])) {
|
||||
$task = $_POST['task'];
|
||||
|
||||
mysqli_query($db, "INSERT INTO tasks (task) VALUES ($tasks)");
|
||||
|
||||
$_SESSION['message'] = "Task Added";
|
||||
header('Location: index.php');
|
||||
}
|
||||
if (isset($_POST['update'])) {
|
||||
$id = $_POST['id'];
|
||||
$task = $_POST['task'];
|
||||
|
||||
mysqli_query($db, "UPDATE tasks SET task='$task' WHERE id='$id'");
|
||||
|
||||
$_SESSION['message'] = "Task Updated!";
|
||||
header('location: index.php');
|
||||
}
|
||||
if (isset($_GET['del'])) {
|
||||
$id = $_GET['del'];
|
||||
mysqli_query($db, "DELETE FROM tasks WHERE id='$id'");
|
||||
$_SESSION['message'] = "Task Removed!";
|
||||
header('Location: index.php');
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
body {
|
||||
font-size: 19px;
|
||||
font-family: 'Arial';
|
||||
}
|
||||
h2 {
|
||||
width: 45%;
|
||||
margin: 50px auto;
|
||||
}
|
||||
table{
|
||||
width: 50%;
|
||||
margin: 30px auto;
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
}
|
||||
tr {
|
||||
border-bottom: 1px solid #cbcbcb;
|
||||
}
|
||||
th, td{
|
||||
border: none;
|
||||
height: 30px;
|
||||
padding: 2px;
|
||||
}
|
||||
tr:hover {
|
||||
background: #F5F5F5;
|
||||
}
|
||||
|
||||
form {
|
||||
width: 45%;
|
||||
margin: 50px auto;
|
||||
text-align: left;
|
||||
padding: 20px;
|
||||
border: 1px solid #bbbbbb;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin: 10px 0px 10px 0px;
|
||||
}
|
||||
.input-group label {
|
||||
display: block;
|
||||
text-align: left;
|
||||
margin: 3px;
|
||||
}
|
||||
.input-group input {
|
||||
height: 30px;
|
||||
width: 93%;
|
||||
padding: 5px 10px;
|
||||
font-size: 16px;
|
||||
border-radius: 5px;
|
||||
border: 1px solid gray;
|
||||
}
|
||||
.btn {
|
||||
padding: 10px;
|
||||
font-size: 15px;
|
||||
color: white;
|
||||
background: #5F9EA0;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.edit_btn {
|
||||
text-decoration: none;
|
||||
padding: 2px 5px;
|
||||
background: #2E8B57;
|
||||
color: white;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.del_btn {
|
||||
text-decoration: none;
|
||||
padding: 2px 5px;
|
||||
color: white;
|
||||
border-radius: 3px;
|
||||
background: #800000;
|
||||
}
|
||||
.msg {
|
||||
margin: 30px auto;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
color: #3c763d;
|
||||
background: #dff0d8;
|
||||
border: 1px solid #3c763d;
|
||||
width: 50%;
|
||||
text-align: center;
|
||||
}
|
||||
Reference in New Issue
Block a user