-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistra_perguntas.php
74 lines (70 loc) · 3.6 KB
/
registra_perguntas.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
<?php
include('header.php');
// Verifica se algo foi enviado
?>
<div class="container">
<div class="row">
<div class="col">
<div class="card-body">
<?php if (!empty( $_POST ) ) {
$nome_form = $_POST['nome_form'];
$nome = $_POST['nome'];
$perguntas = ($_POST['pergunta']);
$perguntasOpcao = $_POST['perguntaOpcao'];
$opcoes = ($_POST['opcao']);
///// INSERE FORMULARIO -> NOME DO FORMULARIO E NOME DO CRIADOR
$sqlInsert = "INSERT INTO nome_formulario (nome_formulario, nome_criador)
VALUES ('$nome_form', '$nome')";
$insert = mysqli_query($db, $sqlInsert);
// SELECIONA O ULTIMO ID INSERIDO NO BANCO DE DADOS (INSERIDO ACIMA)
$selectUltimo = "SELECT id FROM nome_formulario ORDER BY dt_criacao DESC LIMIT 1";
$resultado = mysqli_query($db, $selectUltimo);
$arrayResultado = mysqli_fetch_assoc($resultado);
$id_formulario = $arrayResultado['id'];
if (!empty($perguntas)) {
foreach ($perguntas as $pergunta) {
// INSERIR SE O TIPO FOR TEXTO
$insertPergTexto = "INSERT INTO perguntas (id_formulario, pergunta, is_texto)
VALUES ('$id_formulario', '$pergunta', 'S')";
$insertTexto = mysqli_query($db, $insertPergTexto);
}
}
// INSERCAO DE PERGUNTAS COM OPCOES
if (!empty($perguntasOpcao)) {
// CRIO UM CONTADOR
$cont = 0;
foreach ($perguntasOpcao as $perguntaOpcao){
$opcoes=[];
// UTILIZO O CONT, JÁ QUE PODE EXISTIR VÁRIAS PERGUNTAS COM OPÇÕES
for ($i = $cont; $i <= ($cont+3); $i++){
$opcaoArray = array_push($opcoes, $_POST['opcao'][$i]);
}
$insertPergOpcao = "INSERT INTO perguntas (id_formulario, pergunta, is_opcao, resposta_opcao1,
resposta_opcao2, resposta_opcao3, resposta_opcao4)
VALUES ('$id_formulario', '$perguntaOpcao', 'S', '$opcoes[0]', '$opcoes[1]', '$opcoes[2]', '$opcoes[3]')";
$insertOpcao = mysqli_query($db, $insertPergOpcao);
// AUMENTO O CONT EM 4 PARA CASO TENHA OUTRA PERGUNTA
$cont += 4;
}
} ?>
<h3 class="card-title">FORMULÁRIO CRIADO COM SUCESSO!</h3>
<div class="ml-3 mt-3">
Seu formulário <strong><?php echo($nome_form) ?></strong> foi criado. Você pode utilizar clicando no
'Selecionar formulário.'
</div>
<?php
}
?>
<div class="mt-3">
<a href="index.php">
<button class="btn btn-secondary float-right ml-3">Início</button>
</a>
<a href="selecionar_form.php">
<button class="btn btn-primary float-right">Selecionar formulário</button>
</a>
</div>
</div>
</div>
</div>
</div>
<?php include('footer.php')?>