-
Notifications
You must be signed in to change notification settings - Fork 0
/
createContact.php
37 lines (25 loc) · 972 Bytes
/
createContact.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
<?php
require_once('./includes/connection.php');
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$connection->select_db('contact-main');
if($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$lastname = test_input($_POST["lastname"]);
$address = test_input($_POST["address"]);
$email = test_input($_POST["email"]);
$phone = test_input($_POST["phone"]);
$values = '"' . $name . '","' . $lastname . '","' . $address . '","' . $email . '","' . $phone . '"';
$sql = "INSERT INTO contact (name, lastname, address, email, phone) VALUES (" . $values . ")";
if($connection->query($sql)) {
echo "Contato criado com sucesso. <br>";
header("Location: /contacts");
} else {
echo "Erro na criação do contato: " . $connection->error;
}
$connection->close();
}