banco_projeto/setup/setup.php
2021-09-02 08:27:03 -03:00

39 lines
1.2 KiB
PHP

<?php
if(session_status() !== PHP_SESSION_ACTIVE){
session_start();
}
include('../conexao_publica.php');
$usuario = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$senha = filter_input(INPUT_POST, 'passwd', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING);
$empty = 'vazio';
$nome = 'Administrador';
$tipo='adm';
$sql = "INSERT INTO tbclientes (nome, endereco, bairro, cidade, estado, email, cpf_cnpj, rg) VALUES (?,?,?,?,?,?,?,?)";
$stmt = $con->prepare($sql);
$stmt->bind_param('ssssssss',$nome,$empty,$empty,$empty,$empty,$email,$empty,$empty);
if($stmt->execute())
{
$id=$stmt->insert_id;
$stmt->close();
$sql = "INSERT INTO login_usuarios (login,senha,tipo,id_cliente) VALUES(?,?,?,?)";
$hashed = password_hash($senha,PASSWORD_DEFAULT);
$stmt = $con->prepare($sql);
$stmt->bind_param('ssss',$usuario,$hashed,$tipo,$id);
if($stmt->execute())
{
$_SESSION['msg'] = "Configurado com sucess, por favor faça o login!";
unset($_SESSION['setup']);
}
else{
$_SESSION['msg'] = "Erro no cadastro!";
}
$stmt->close();
header('Location: ../index.php');
}
?>