-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiCrud.php
44 lines (36 loc) · 1.44 KB
/
apiCrud.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
<?php
include_once 'dbConn.php';
if(isset($_POST['submit'])){
$nome = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$profissao = $_POST['occupation'];
$money = $_POST['investment_money'];
$city = $_POST['city'];
$bairro = $_POST['neighborhood'];
$message = $_POST['message'];
//print_r(array($nome, $email, $phone, $profissao, $money, $city, $bairro, $message));
dbInsert($nome, $email, $phone, $profissao, $money, $city, $bairro, $message);
dbDelete(1);
$table = dbRead();
}
function dbInsert($nome, $email, $phone, $profissao, $money, $city, $bairro, $message){
global $conn;
$query = 'INSERT INTO contatos(nome, email, telefone, profissao, capital_de_investimento, cidade, bairro, mensagem)
VALUES (:nome, :email, :telefone, :profissao, :capital, :cidade, :bairro, :mensagem)';
$stmt = $conn->prepare($query);
$stmt->execute(array(':nome'=>$nome, ':email'=>$email, ':telefone'=> $phone,':profissao' => $profissao,':capital' => $money,':cidade' => $city, ':bairro' => $bairro, ':mensagem' => $message));
header("Location: index.php?inseridocomsucesso");
}
function dbDelete($id){
global $conn;
$query = 'DELETE FROM contatos WHERE id = :id';
$stmt = $conn->prepare($query);
$stmt->execute(array(':id'=>$id));
}
function dbRead(){
global $conn;
$query = 'SELECT * FROM contatos';
$stmt = $conn->query($query);
return $stmt->fetch();
}