-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrar_usuario.php
48 lines (35 loc) · 1.2 KB
/
registrar_usuario.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
<?php
require_once('config.php');
$nome = $_POST['nome'];
$email = $_POST['email'];
$senha = md5($_POST['senha']); // MD5 = Criptografia
$csenha = md5($_POST['csenha']);
$cargo = $_POST['cargo'];
$objDb = new db();
$link = $objDb->conecta_mysql();
$email_existe = false;
if($senha == $csenha){ // Confirmação da senha
// Verificar se o email já esta cadastrado
$sql = " SELECT * FROM usuarios WHERE email = '$email'";
if($resultado_id = mysqli_query($link, $sql)){
$dados_usuario = mysqli_fetch_array($resultado_id);
if(isset($dados_usuario['email'])){
echo 'Email já cadastrado';
$email_existe = true;
}
}else {
echo 'Erro ao tentar localizar o registro';
}
if($email_existe == true){
header('Location: cadastro.php?erro_email=1');
}
$sql = "INSERT INTO usuarios (nome, email, senha, cargo) values ('$nome', '$email', '$senha', '$cargo')";
if (mysqli_query($link, $sql)){
header('Location: index.php.?sucesso=1');
} else {
echo 'Erro ao registrar usuario!';
}
}else{
header('Location: cadastro.php.?erro=1');
}
?>