-
Notifications
You must be signed in to change notification settings - Fork 0
/
carPost.php
80 lines (64 loc) · 2.21 KB
/
carPost.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
<?php
require_once "mail.php";
require_once "dbase_connection.php";
$connection = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
mysqli_set_charset($connection,'utf8mb4_general_ci');
// Get the posted data.
$postdata = file_get_contents("php://input");
if(!$postdata)exit;
$request = json_decode($postdata);
// test for connection
if (mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" ( " . mysqli_connect_errno() . ")");
}
$fullName = mysqli_real_escape_string($connection, trim($request->fullname));
$email = mysqli_real_escape_string($connection, trim($request->email));
$account = mysqli_real_escape_string($connection, trim($request->account));
$supervisor = mysqli_real_escape_string($connection, trim($request->supervisor));
$dates = $request->selectedDays;
$le=count($dates);
for($i=0;$i<$le;$i++){
$dates[$i]=date('d-n-Y', $dates[$i]);
}
$unit=$request->unit;
$comments = mysqli_real_escape_string($connection, trim($request->comments));
$tablename = $request->table;
$status=$request->status;
if($status == 1){
$confirm="Confirmed!";
}else{
$confirm= " !! Confirmation pending !!";
}
/* $status = 1;
if($tablename == "blue_hilux" || $tablename == "red_hilux"){
$status =0;
}*/
$query = "SELECT * FROM inits WHERE unit = '$tablename' ";
$result = mysqli_query( $connection, $query );
if ( !$result ) {
die( "Database query failed" );
} else {
while ( $row = mysqli_fetch_assoc( $result ) ) {
$secondEmail= $row[ 'emailOne' ];
$thirdEmail= $row[ 'emailTwo' ];
$message=$row['message'];
}
}
foreach ($dates as $date) {
$query = "INSERT INTO $tablename (";
$query .= "status,fullName,email,account,";
$query .= "supervisor, date, comments";
$query .= ") VALUES (";
$query .= "'${status}','${fullName}','${email}', '${account}',";
$query .= "'${supervisor}','${date}','${comments}' ";
$query .= ")";
$result = (mysqli_query($connection, $query));
}
mysqli_close($connection);
$datesImpl= implode(", ", $dates);
require "emailItems/emailitemCar.php";
$message = sendMail($fullName,$account,$email,$secondEmail,$thirdEmail,$html);
echo $message;
?>