-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
148 lines (126 loc) · 5.29 KB
/
update.php
File metadata and controls
148 lines (126 loc) · 5.29 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
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
139
140
141
142
143
144
145
146
147
148
<?php
require 'banco.php';
$id = null;
if (!empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if (null == $id) {
header("Location: index.php");
}
if (!empty($_POST)) {
$tipoErro = null;
$cantorErro = null;
$descricaoErro = null;
$tipo = $_POST['tipo'];
$cantor = $_POST['cantor'];
$descricao = $_POST['descricao'];
//Validação
$validacao = true;
if (empty($tipo)) {
$tipoErro = 'Por favor digite o tipo!';
$validacao = false;
}
if (empty($cantor)) {
$cantorErro = 'Por favor digite canto!';
$validacao = false;
} else if (!filter_var($cantor, FILTER_SANITIZE_STRING)) {
$cantorErro = 'Por favor digite cantor!';
$validacao = false;
}
if (empty($descricao)) {
$descricaoErro = 'Por favor digite uma descricao';
$validacao = false;
}
// update data
if ($validacao) {
$pdo = Banco::conectar();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE discos set tipo = ?, cantor = ?, descricao = ? WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($tipo, $cantor, $descricao, $id));
Banco::desconectar();
header("Location: index.php");
}
} else {
$pdo = Banco::conectar();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM discos where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$tipo = $data['tipo'];
$cantor = $data['cantor'];
$descricao = $data['descricao'];
Banco::desconectar();
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<!-- using new bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Atualizar Discos</title>
</head>
<body>
<div class="container">
<div class="span10 offset1">
<div class="card">
<div class="card-header">
<h3 class="well"> Atualizar Discos </h3>
</div>
<div class="card-body">
<form class="form-horizontal" action="update.php?id=<?php echo $id ?>" method="post">
<div class="control-group <?php echo !empty($tipoErro) ? 'error' : ''; ?>">
<label class="control-label">Tipo</label>
<div class="controls">
<input name="tipo" class="form-control" size="50" type="text" placeholder="Tipo"
value="<?php echo !empty($tipo) ? $tipo : ''; ?>">
<?php if (!empty($tipoErro)): ?>
<span class="text-danger"><?php echo $tipoErro; ?></span>
<?php endif; ?>
</div>
</div>
<div class="control-group <?php echo !empty($cantorErro) ? 'error' : ''; ?>">
<label class="control-label">Cantor</label>
<div class="controls">
<input name="cantor" class="form-control" size="80" type="text" placeholder="Cantor"
value="<?php echo !empty($cantor) ? $cantor : ''; ?>">
<?php if (!empty($cantorErro)): ?>
<span class="text-danger"><?php echo $cantorErro; ?></span>
<?php endif; ?>
</div>
</div>
<div class="control-group <?php echo !empty($descricaoErro) ? 'error' : ''; ?>">
<label class="control-label">descricao</label>
<div class="controls">
<input name="descricao" class="form-control" size="30" type="text" placeholder="Descrição"
value="<?php echo !empty($descricao) ? $descricao : ''; ?>">
<?php if (!empty($descricaoErro)): ?>
<span class="text-danger"><?php echo $descricaoErro; ?></span>
<?php endif; ?>
</div>
</div>
</div>
<br/>
<div class="form-actions">
<button type="submit" class="btn btn-warning">Atualizar</button>
<a href="index.php" type="btn" class="btn btn-default">Voltar</a>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="assets/js/bootstrap.min.js"></script>
</body>
</html>