-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patho_loc.php
More file actions
51 lines (43 loc) · 2.09 KB
/
o_loc.php
File metadata and controls
51 lines (43 loc) · 2.09 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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: application/json');
$servername = "localhost";
$username = "root"; // Your XAMPP MySQL username
$password = ""; // Your XAMPP MySQL password (empty by default)
$dbname = "owner_registration"; // Your Database Name
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection Failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$owner_id = $_POST['owner_id'];
$car_number = $_POST['car_number'];
$source = $_POST['source'];
$destination = $_POST['destination'];
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$timestamp = date("Y-m-d H:i:s");
if (!empty($owner_id) && !empty($car_number) && !empty($source) && !empty($destination) && !empty($latitude) && !empty($longitude)) {
$stmt = $conn->prepare("SELECT * FROM cars WHERE registration_number = ? AND owner_id = ?");
$stmt->bind_param("si", $car_number, $owner_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$stmt = $conn->prepare("INSERT INTO owner_locations (owner_id, car_registration_number, source_location, destination_location, latitude, longitude, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("isssdds", $owner_id, $car_number, $source, $destination, $latitude, $longitude, $timestamp);
if ($stmt->execute()) {
echo json_encode(["status" => "success", "message" => "Trip Saved Successfully"]);
} else {
echo json_encode(["status" => "error", "message" => "Failed to Save Trip"]);
}
} else {
echo json_encode(["status" => "error", "message" => "Car Registration Number Not Linked with this Owner"]);
}
} else {
echo json_encode(["status" => "error", "message" => "Incomplete Data"]);
}
} else {
echo json_encode(["status" => "error", "message" => "Invalid Request"]);
}
?>