-
Notifications
You must be signed in to change notification settings - Fork 0
/
cadastro.php
105 lines (86 loc) · 3.49 KB
/
cadastro.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
<?php
require('conecxaoBD.php');
if (isset($_POST['nome']) || isset($_POST['email']) || isset($_POST['senha'])) {
if (strlen($_POST['nome']) == 0) {
echo "preencha seu nome";
} else if (strlen($_POST['email']) == 0) {
echo "preencha seu email";
} else if (strlen($_POST['senha']) == 0) {
echo "preencha seu senha";
} else {
$email = $_POST['email'];
$stmt = $database->query("SELECT * FROM usuario WHERE email = '$email'");
$usuario = $stmt->fetch();
if (!$usuario) {
$stmt = $database->prepare('INSERT INTO usuario (nome, email, senha) VALUES(:nome, :email, :senha)');
$stmt->execute(array(
':nome' => $_POST['nome'],
':email' => $_POST['email'],
':senha' => $_POST['senha']
));
$stmt = $database->query("SELECT * FROM usuario WHERE email = '$email'");
$usuario = $stmt->fetch();
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['id'] = $usuario['id'];
$_SESSION['nome'] = $usuario['nome'];
header('Location: index.php');
} else {
echo "Email já cadsatrado";
}
}
}
?>
<!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">
<title>Cadastro - Site Critica</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<header>
<div class="menu">
<div id="logo">
<a href="index.php"><img src="img/pipoca.png" alt="Logo"></a>
</div>
<nav>
<a href="index.php">Voltar</a>
</nav>
</div>
</header>
<main>
<div class="container">
<h2 align="center">Cadastro de Usuário</h2>
<div class="col-md-4" style="margin:0 auto; float:none;">
<form class="form_ec " action="" method="post">
<div class="form-group">
<label for="nome">Nome: </label>
<input type="text" name="nome" placeholder="insira o título" class="form-control"/>
</div>
<div class="form-group">
<label for="email">Email: </label>
<input type="email" name="email" placeholder="insira o título" class="form-control"/>
</div>
<div class="form-group">
<label for="senha">senha: </label>
<input type="password" name="senha" placeholder="insira o título" class="form-control"/>
</div>
<div class="form-group" align="center">
<button type="submit" class="btn btn-info">Cadastrar</button>
</div>
<div class="form-group" align="center">
<a href="entrar.php">Já possuo uma conta</a>
</div>
</form>
</div>
</div>
</main>
</body>
</html>