-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
138 lines (122 loc) · 4.86 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
include "class/Crud.php";
include "class/Connection.php";
include "assets/function/formatAge.php";
$conn = new Connection();
if(isset($_POST["create"],$_POST["name"],$_POST["age"])) {
$user = [
"name" => $_POST["name"],
"age" => $_POST["age"],
];
$conn->create($user);
}
if(isset($_POST["delele"])) {
$conn->delete($_POST["id"]);
}
if(isset($_POST["update"])) {
$id = $_POST['id'];
header("Location: updateUser.php?id=$id");
}
$users = $conn->read(True);
?>
<!DOCTYPE html>
<html lang="pt-br">
<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="shortcut icon" href="./assets/image/favicon.svg" type="image/x-icon">
<title>CRUD PHP</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="./assets/css/style.css">
</head>
<body>
<header class="container">
<h1 class="text-center">CRUD o que e?</h1>
</header>
<div class="container">
<main>
<div class="text-center">
<h2>CRUD</h2>
</div>
<div class="row">
<p>CRUD e uma sigla para falar das 4 operações básicas de um banco de dados, Insert, Select, Update e
Delete.</p>
<ul>
<li>C - CREATE</li>
<li>R - READ</li>
<li>U - UPDATE</li>
<li>D - DELETE</li>
</ul>
</div>
<div class="row">
<div class="col">
<h3>CREATE</h3>
<p>Criar um novo registro.</p>
</div>
<div class="col">
<h3>READ</h3>
<p>Ler um registro, ou uma lista de registros.</p>
</div>
<div class="col">
<h3>UPDATE</h3>
<p>Atualizar um registro.</p>
</div>
<div class="col">
<h3>DELETE</h3>
<p>Excluir um registro.</p>
</div>
</div>
<div>
<form class="row" id="from-create" action="index.php" method="post">
<div class="form-group text-center">
<h1>Insira os dados para aparecer na tabela</h1>
</div>
<div class="form-group">
<label for="name">Nome</label>
<input class="form-control" placeholder="digite o nome" id="name" name="name" type="text" required>
</div>
<div class="form-group">
<label for="age">Idade</label>
<input class="form-control" placeholder="digite a idade" id="age" name="age" type="number" required>
</div>
<div class="form-group mt-2">
<input class="btn btn-primary" type="submit" name="create" value="Enviar">
</div>
</form>
</div>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Nome</th>
<th scope="col">Idade</th>
<th scope="col">Comandos</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user):?>
<tr>
<td><?=$user["name"]; ?></td>
<td><?= formatAge($user["age"]);?></td>
<td>
<form action="index.php" id="form-delete" method="post">
<input type='hidden' name='id' value=<?= $user["id"] ?>>
<button type="submit" name="update" class="btn btn-outline-primary">Editar</button>
<button type="submit" name="delele" class="btn btn-danger">Deletar</button>
</form>
</td>
</tr>
<?php endforeach?>
</tbody>
</table>
</main>
<footer class="footer">
<p>feito por Natan Xavier.</p>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
</body>
</html>