-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_add_car.php
38 lines (29 loc) · 1.17 KB
/
process_add_car.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
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$brand = $_POST["brand"];
$model = $_POST["model"];
$seats = $_POST["seats"];
$licensePlate = $_POST["licensePlate"];
$engineType = $_POST["engineType"];
$currentAutonomy = $_POST["currentAutonomy"];
$targetDir = "uploads/";
$targetFile = $targetDir . basename($_FILES["image"]["name"]);
move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile);
// Insert data into the database
$conn = new mysqli("localhost", "root", "", "ctw");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Car (brand, model, seats, licensePlate, engineType, currentAutonomy, image)
VALUES ('$brand', '$model', $seats, '$licensePlate', '$engineType', $currentAutonomy, '$targetFile')";
if ($conn->query($sql) === TRUE) {
$_SESSION['success_message'] = "Car added successfully!";
} else {
$_SESSION['error_message'] = "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
header("Location: add_car.php");
?>