End of Day
This commit is contained in:
parent
09ad98ba14
commit
7eb0302faa
35
action.php
Normal file
35
action.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
include_once "errors.php";
|
||||||
|
include_once "headers.php";
|
||||||
|
include_once "database.php";
|
||||||
|
|
||||||
|
$act = $_POST["act"];
|
||||||
|
|
||||||
|
switch ($act) {
|
||||||
|
case "add": {
|
||||||
|
$db = DB::openConnection();
|
||||||
|
|
||||||
|
$insert = "INSERT INTO users(Name) VALUES(:NAME)";
|
||||||
|
|
||||||
|
$stmt = $db->prepare($insert);
|
||||||
|
$stmt->bindParam(":NAME", $_POST["name"]);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
DB::closeConnection($db);
|
||||||
|
}
|
||||||
|
case "rem": {
|
||||||
|
$db = DB::openConnection();
|
||||||
|
|
||||||
|
$insert = "DELETE FROM users WHERE ID = :ID";
|
||||||
|
|
||||||
|
$stmt = $db->prepare($insert);
|
||||||
|
$stmt->bindParam(":ID", $_POST["ID"]);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
DB::closeConnection($db);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Headers::redirect(".");
|
||||||
13
headers.php
13
headers.php
@ -3,6 +3,19 @@ class Headers
|
|||||||
{
|
{
|
||||||
static function json()
|
static function json()
|
||||||
{
|
{
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
header("Content-Type: text/json");
|
header("Content-Type: text/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function html()
|
||||||
|
{
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
static function redirect(string $newUrl, bool $permanent = FALSE)
|
||||||
|
{
|
||||||
|
header('Location: ' . $newUrl, true, $permanent ? 301 : 302);
|
||||||
|
|
||||||
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
index.css
Normal file
56
index.css
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
*, ::after, ::before {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #212529;
|
||||||
|
text-align: left;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.col {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
margin: 10px;
|
||||||
|
overflow: scroll;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list .item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list .item .marker {
|
||||||
|
width: 40px;
|
||||||
|
text-align: end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list .item .content {
|
||||||
|
width: 100%;
|
||||||
|
text-align: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add {
|
||||||
|
margin: 10px;
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add input[name="name"] {
|
||||||
|
width: 100%
|
||||||
|
}
|
||||||
62
index.php
62
index.php
@ -1,17 +1,55 @@
|
|||||||
<?php
|
<!DOCTYPE html>
|
||||||
include_once "errors.php";
|
<html lang="de">
|
||||||
include_once "headers.php";
|
|
||||||
Headers::json();
|
|
||||||
include_once "database.php";
|
|
||||||
|
|
||||||
$db = DB::openConnection();
|
<head>
|
||||||
|
<link href="index.css" rel="stylesheet" />
|
||||||
|
|
||||||
$query = "SELECT * FROM users";
|
<meta charset="utf-8" />
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
|
||||||
$stmt = $db->prepare($query);
|
<title>PHP Course</title>
|
||||||
$stmt->execute();
|
</head>
|
||||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
DB::closeConnection($db);
|
<body>
|
||||||
|
<?php
|
||||||
|
include_once "errors.php";
|
||||||
|
include_once "headers.php";
|
||||||
|
Headers::html();
|
||||||
|
include_once "database.php";
|
||||||
|
|
||||||
echo json_encode($result);
|
$db = DB::openConnection();
|
||||||
|
|
||||||
|
$query = "SELECT * FROM users ORDER BY ID";
|
||||||
|
|
||||||
|
$stmt = $db->prepare($query);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
DB::closeConnection($db);
|
||||||
|
?>
|
||||||
|
<div class="col">
|
||||||
|
<div class="list">
|
||||||
|
<?php
|
||||||
|
foreach ($result as $index => $item) {
|
||||||
|
?>
|
||||||
|
<div class="item">
|
||||||
|
<span class="marker"><?= $index + 1 ?></span>
|
||||||
|
<span class="content"><?= $item["Name"] ?></span>
|
||||||
|
<form action="action.php" method="post">
|
||||||
|
<input type="hidden" name="ID" value="<?= $index + 1 ?>" />
|
||||||
|
<button name="act" value="rem">Entfernen</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<form action="action.php" method="post" class="add">
|
||||||
|
<label >Name:</label>
|
||||||
|
<input name="name" placeholder="Name" required />
|
||||||
|
<button name="act" value="add">Hinzufügen</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user