-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertClient.php
More file actions
77 lines (60 loc) · 2.44 KB
/
insertClient.php
File metadata and controls
77 lines (60 loc) · 2.44 KB
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
<?php
require 'db.php';
if (empty($_POST['client'])) {
http_response_code(500);
exit('No client');
}
$client = $_POST['client'];
$regularDay = $client['regularDay'];
$friday = $client['friday'];
if(!empty($client['specialDay'])){
$specialDay = $client['specialDay'];
} else {
$specialDay = '';
}
$query1 = 'INSERT INTO `client_names`(`id`, `name`) VALUES (null, :name)';
$query2 = 'INSERT INTO `reg_day_hours`(`client_id`, `hours`, `minutes`) VALUES (:id,:hours,:minutes)';
$query3 = 'INSERT INTO `friday_hours`(`client_id`, `hours`, `minutes`) VALUES (:id,:hours,:minutes)';
$query4 = 'INSERT INTO `special_day`(`client_id`, `day`, `hours`, `minutes`) VALUES (:id,:day,:hours,:minutes)';
$statement = $db->prepare($query1);
$statement->bindParam(':name', $client['name']);
$rowsInserted = $statement->execute();
if($rowsInserted) {
$id = $db->lastInsertId();
}
else {
http_response_code(500);
exit('Unable to add contact');
}
$statement = $db->prepare($query2);
$statement->bindParam(':id', $id);
$statement->bindParam(':hours', $regularDay['hours']);
$statement->bindParam(':minutes', $regularDay['minutes']);
$rowsInserted = $statement->execute();
if(!$rowsInserted) {
http_response_code(500);
exit('Unable to add regularDay hours');
}
$statement = $db->prepare($query3);
$statement->bindParam(':id', $id);
$statement->bindParam(':hours', $friday['hours']);
$statement->bindParam(':minutes', $friday['minutes']);
$rowsInserted = $statement->execute();
if(!$rowsInserted) {
http_response_code(500);
exit('Unable to add friday hours');
}
if(!empty($specialDay)) {
$statement = $db->prepare($query4);
$statement->bindParam(':id', $id);
$statement->bindParam(':day', $specialDay['day']);
$statement->bindParam(':hours', $specialDay['hrsAndMin']['hours']);
$statement->bindParam(':minutes', $specialDay['hrsAndMin']['minutes']);
$rowsInserted = $statement->execute();
if(!$rowsInserted) {
http_response_code(500);
exit('Unable to add specialDay hours');
}
}
echo('Client Added Succesfully');
?>