-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
97 lines (83 loc) · 4.08 KB
/
update.php
File metadata and controls
97 lines (83 loc) · 4.08 KB
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
<?php
include "conexao.php";
if(isset($_GET['id'])){
$id = $_GET['id'];
$sql = "SELECT * FROM livros WHERE id = $id";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
}
if($_SERVER["REQUEST_METHOD"]=="POST"){
$titulo = $_POST['titulo'];
$autor = $_POST['autor'];
$anoPublicacao = $_POST['ano'];
$genero = $_POST['genero'];
$editora = $_POST['editora'];
$sql = "UPDATE livros SET titulo='$titulo', autor='$autor', ano='$anoPublicacao', genero='$genero', editora='$editora' WHERE id = $id";
$result = mysqli_query($conn, $sql);
if($result){
header("Location: index.php");
exit();
} else{
echo "Erro ao editar o livro.";
die("Erro ao gravar: " . mysqli_error($conn));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel=" stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="
sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="
sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="
sha384-Rx+T1VzGupg4BHQYs2gCW9It+akI2MM/mndMCy36UVfodzcJcF0GGLxZIzObiEfa" crossorigin="anonymous"></script>
<div class="container">
<h2>Add new book</h2>
<form method="POST" action="">
<form method="POST" action="">
<div class="mb-3">
<label class="form-label" for="titulo">Título:</label>
<input class="form-control" type="text" name="titulo" value="<?php echo $row['titulo']; ?>"
maxlength="40" required><br>
</div>
<div class="mb-3">
<label class="form-label" for="autor">Autor:</label>
<input class="form-control" type="text" name="autor" value="<?php echo $row['autor']; ?>"
maxlength="30" required><br>
</div>
<div class="mb-3">
<label class="form-label" for="ano">Ano de Publicação:</label>
<input class="form-control" type="number" name="ano" value="<?php echo $row['ano']; ?>"
required><br>
</div>
<div class="mb-3">
<label class="form-label" for="editora">Editora:</label>
<input class="form-control" type="text" name="editora" value="<?php echo $row['editora']; ?>"
maxlength="30" required><br>
</div>
<label class="form-label" for="genero">Gênero:</label>
<select class="form-select" id="genero" name="genero" required>
<option value="<?php echo $row['genero']; ?>" selected><?php echo $row['genero']; ?></option>
<option value="Programação">Programação</option>
<option value="Design">Design</option>
<option value="Política">Política</option>
<option value="Religião">Religião</option>
<option value="Filhos">Criação de Filhos</option>
<option value="Ficcao">Ficção Científica</option>
<option value="Outros">Outros</option>
</select><br />
<input class="btn btn-primary" type="submit" value="Adicionar Livro">
<a class="btn btn-secondary" href="index.php">Voltar</a>
</form>
</form>
</div>
</body>
</html>