-
Notifications
You must be signed in to change notification settings - Fork 0
/
inserir_registo.php
89 lines (66 loc) · 2.46 KB
/
inserir_registo.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
<html>
<body>
<h2>Bloco de Notas</h2>
<h4>Retirar página</h4>
<?php
session_start();
include 'functions.php';
echo("<h5>Sessão de {$_SESSION['nome']} </h5>");
$connection=createConnection();
$nCampos = $_SESSION['counter'];
$arrayValoresCampos = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
for ($i = 0; $i <= $nCampos; $i++) {
array_push($arrayValoresCampos, test_input($_POST["$i"]));
}
}
$typecnt = $_SESSION['typecnt'];
$nomeRegisto = $_SESSION['nomeRegisto'];
$pageId = $_SESSION['pageId'];
try{
$connection->beginTransaction();
$regCounter = geraId('regcounter', 'registo', $connection);
//obter os campos do tipo de registo
$i=0;
$sql = "SELECT campocnt FROM campo WHERE userid=".$_SESSION['id']." AND typecnt=$typecnt";
$result = $connection->query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$rows = $result->fetchAll();
//inserir novo registo
$idSeq = geraIdSeq($connection);
$sql = "INSERT INTO registo (userid, typecounter, regcounter, nome, ativo, idseq, pregcounter)
VALUES (".$_SESSION['id'].", $typecnt, $regCounter, '$nomeRegisto', 1, $idSeq, NULL)";
if ($connection->query($sql) === FALSE) {
die( "Error: " . $sql . "<br>" . $conn->error);
}
//inserir novos valores nos campos
foreach ($rows as $row){
$i++;
$idSeq = geraIdSeq($connection);
$sql = "INSERT INTO valor (userid, typeid, regid, campoid, valor, idseq, ativo, pcampoid)
VALUES (".$_SESSION['id'].", $typecnt, $regCounter, ".$row[campocnt].", '$arrayValoresCampos[$i]', $idSeq, 1, NULL)";
if ($connection->query($sql) === FALSE) {
die( "Error: " . $sql . "<br>" . $conn->error);
}
}
//inserir registo na pagina
$idSeq = geraIdSeq($connection);
$sql = "INSERT INTO reg_pag (userid, pageid, typeid, regid, idseq, ativa, pidregpag)
VALUES (".$_SESSION['id'].", $pageId, $typecnt, $regCounter, $idSeq, 1, NULL)";
if ($connection->query($sql) === FALSE) {
die( "Error: " . $sql . "<br>" . $conn->error);
}
$connection->commit();
} catch (Exception $e) {
$connection->rollBack();
echo "Failed: " . $e->getMessage();
}
echo("<br></br>");
echo("<p>Registo inserido com sucesso</p>");
buttons();
$connection->close();
?>
</body>
</html>