-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
127 lines (109 loc) · 4.67 KB
/
create.php
File metadata and controls
127 lines (109 loc) · 4.67 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
<?php
require 'banco.php';
//Acompanha os erros de validação
// Processar so quando tenha uma chamada post
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$tipoErro = null;
$cantorErro = null;
$descricaoErro = null;
if (!empty($_POST)) {
$validacao = True;
$novoUsuario = False;
if (!empty($_POST['tipo'])) {
$tipo = $_POST['tipo'];
} else {
$tipoErro = 'Por favor digite o tipo!';
$validacao = False;
}
if (!empty($_POST['cantor'])) {
$cantor = $_POST['cantor'];
} else {
$cantorErro = 'Por favor digite o nome do cantor!';
$validacao = False;
}
if (!empty($_POST['descricao'])) {
$descricao = $_POST['descricao'];
} else {
$descricaoErro = 'Por favor digite uma descrição!';
$validacao = False;
}
}
//Inserindo no Banco:
if ($validacao) {
$pdo = Banco::conectar();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO discos (tipo, cantor, descricao) VALUES(?,?,?)";
$q = $pdo->prepare($sql);
$q->execute(array($tipo, $cantor, $descricao));
Banco::desconectar();
header("Location: index.php");
}
}
?>
<!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">
<title>Adicionar Discos</title>
</head>
<body>
<div class="container">
<div clas="span10 offset1">
<div class="card">
<div class="card-header">
<h3 class="well"> Adicionar Discos </h3>
</div>
<div class="card-body">
<form class="form-horizontal" action="create.php" method="post">
<div class="control-group <?php echo !empty($tipoErro) ? 'error ' : ''; ?>">
<label class="control-label">Tipo</label>
<div class="controls">
<input size="50" class="form-control" name="tipo" 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 size="80" class="form-control" name="cantor" type="text" placeholder="Cantor"
value="<?php echo !empty($endereco) ? $endereco : ''; ?>">
<?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">Descrição</label>
<div class="controls">
<input size="35" class="form-control" name="descricao" type="text" placeholder="Descricao"
value="<?php echo !empty($descricao) ? $descricao : ''; ?>">
<?php if (!empty($telefoneErro)): ?>
<span class="text-danger"><?php echo $descricaoErro; ?></span>
<?php endif; ?>
</div>
</div>
<div class="form-actions">
<br/>
<button type="submit" class="btn btn-success">Adicionar</button>
<a href="index.php" type="btn" class="btn btn-default">Voltar</a>
</div>
</form>
</div>
</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>