forked from marciofunes/crud_fatec_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcadastro.php
105 lines (83 loc) · 2.43 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
header('Access-Control-Allow-Origin: *');
$connect = new PDO("https://freshmark.000webhostapp.com/;id20420990_leonardo1234","id20420990_leonardohenrique",">~2M/e*mXc>ie-Yx");
$received_data = json_decode(file_get_contents("php://input"));
$data = array();
if ($received_data->action == 'fetchall') {
$query = "
SELECT * FROM Professores
ORDER BY id DESC
";
$statement = $connect->prepare($query);
$statement->execute();
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
$data[] = $row;
}
echo json_encode($data);
}
if ($received_data->action == 'insert') {
$data = array(
':nome' => $received_data->nome,
':endereco' => $received_data->endereco,
':curso' => $received_data->curso,
':salario' => $received_data->salario
);
$query = "
INSERT INTO Professores
(nome, endereco, curso, salario)
VALUES (nome, endereco, curso, salario)
";
$statement = $connect->prepare($query);
$statement->execute($data);
$output = array(
'message' => 'Professor Adicionado'
);
echo json_encode($output);
}
if ($received_data->action == 'fetchSingle') {
$query = "
SELECT * FROM Professores
WHERE id = '" . $received_data->id . "'
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach ($result as $row) {
$data['id'] = $row['id'];
$data['first_name'] = $row['first_name'];
$data['last_name'] = $row['last_name'];
}
echo json_encode($data);
}
if ($received_data->action == 'update') {
$data = array(
':first_name' => $received_data->firstName,
':last_name' => $received_data->lastName,
':id' => $received_data->hiddenId
);
$query = "
UPDATE fatec_alunos
SET first_name = :first_name,
last_name = :last_name
WHERE id = :id
";
$statement = $connect->prepare($query);
$statement->execute($data);
$output = array(
'message' => 'Aluno Atualizado'
);
echo json_encode($output);
}
if ($received_data->action == 'delete') {
$query = "
DELETE FROM fatec_alunos
WHERE id = '" . $received_data->id . "'
";
$statement = $connect->prepare($query);
$statement->execute();
$output = array(
'message' => 'Aluno Deletado'
);
echo json_encode($output);
}
?>