-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.php
41 lines (30 loc) · 1.4 KB
/
insert.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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: POST");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
require_once('database.php');
$database = new Database();
$conn = $database->connect();
$datos = json_decode(file_get_contents("php://input"));
$msg['message'] = '';
if(isset($datos->title) && isset($datos->priority) && isset($datos->description)){
if(!empty($datos->title) && !empty($datos->priority) && !empty($datos->description)){
$query = "INSERT INTO task(title,priority,description) VALUES(:title,:priority,:description)";
$stmt = $conn->prepare($query);
$stmt->bindValue(':title', htmlspecialchars($datos->title), PDO::PARAM_STR);
$stmt->bindValue(':priority', htmlspecialchars($datos->priority), PDO::PARAM_STR);
$stmt->bindValue(':description', htmlspecialchars($datos->description), PDO::PARAM_STR);
if( $stmt->execute()){
$msg['message'] = 'Datos insertados correctamente';
} else{
$msg['message'] = 'Datos no insertados :(';
}
} else{
$msg['message'] = 'Algunos campos pueden estar vacios';
}
} else{
$msg['message'] = 'Por favor inserte todos los campos';
}
echo json_encode($msg);