<?php
include 'db_config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $driver_name = $_POST['driver_name'];
    $phone = $_POST['phone'];
    $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
    $driver_email = $_POST['driver_email'];
    $created_at = date("Y-m-d H:i:s");

    $sql = "INSERT INTO registered_vehicles (driver_name, phone, password, driver_email, created_at) VALUES ('$driver_name', '$phone', '$password', '$driver_email', '$created_at')";

    if ($conn->query($sql) === TRUE) {
        echo "Registration successful!";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <h1>Register</h1>
    <form method="POST" action="register.php">
        <label for="driver_name">Driver Name:</label>
        <input type="text" name="driver_name" id="driver_name" required><br>
        <label for="phone">Phone:</label>
        <input type="text" name="phone" id="phone" required><br>
        <label for="password">Password:</label>
        <input type="password" name="password" id="password" required><br>
        <label for="driver_email">Driver Email:</label>
        <input type="email" name="driver_email" id="driver_email" required><br>
        <button type="submit">Register</button>
    </form>
</body>
</html>
