108 lines
5.4 KiB
PHP
108 lines
5.4 KiB
PHP
<?php
|
|
$page_title = "Sell My Car - AFG CARS";
|
|
include '../includes/header.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: ' . APP_URL . 'login.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
$error = '';
|
|
$success = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$title = $_POST['title'];
|
|
$brand = $_POST['brand'];
|
|
$model = $_POST['model'];
|
|
$year = $_POST['year'];
|
|
$price = $_POST['price'];
|
|
$location = $_POST['location'];
|
|
$fuel = $_POST['fuel_type'];
|
|
$transmission = $_POST['transmission'];
|
|
$mileage = $_POST['mileage'];
|
|
$desc = $_POST['description'];
|
|
$image = $_POST['image'];
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO cars (user_id, title, brand, model, year, price, location, fuel_type, transmission, mileage, description, image, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')");
|
|
$stmt->execute([$user_id, $title, $brand, $model, $year, $price, $location, $fuel, $transmission, $mileage, $desc, $image]);
|
|
$success = "Listing submitted! Waiting for admin approval.";
|
|
} catch (PDOException $e) {
|
|
$error = "Error: " . $e->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="mb-4">
|
|
<a href="dashboard.php" class="btn btn-link text-decoration-none p-0 mb-2"><i class="bi bi-arrow-left"></i> Back to Dashboard</a>
|
|
<h2 class="fw-bold">List Your Car for Sale</h2>
|
|
<p class="text-muted">Enter accurate details to get better responses from buyers.</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?><div class="alert alert-danger rounded-4"><?php echo $error; ?></div><?php endif; ?>
|
|
<?php if ($success): ?><div class="alert alert-success rounded-4"><?php echo $success; ?></div><?php endif; ?>
|
|
|
|
<div class="bg-white p-4 p-md-5 rounded-4 shadow-sm border">
|
|
<form method="POST">
|
|
<div class="row g-4">
|
|
<div class="col-12">
|
|
<label class="form-label fw-bold">Listing Title</label>
|
|
<input type="text" name="title" class="form-control form-control-lg rounded-3" required placeholder="e.g. 2021 Lexus LX570 White Exterior">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Brand</label>
|
|
<input type="text" name="brand" class="form-control rounded-3" required placeholder="e.g. Toyota">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Model</label>
|
|
<input type="text" name="model" class="form-control rounded-3" required placeholder="e.g. Corolla">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label fw-bold">Year</label>
|
|
<input type="number" name="year" class="form-control rounded-3" required placeholder="2022">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label fw-bold">Price ($)</label>
|
|
<input type="number" name="price" class="form-control rounded-3" required placeholder="25000">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label fw-bold">Location</label>
|
|
<select name="location" class="form-select rounded-3">
|
|
<option>Kabul</option><option>Herat</option><option>Mazar-i-Sharif</option><option>Kandahar</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Fuel Type</label>
|
|
<input type="text" name="fuel_type" class="form-control rounded-3" placeholder="Petrol / Diesel">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Transmission</label>
|
|
<select name="transmission" class="form-select rounded-3">
|
|
<option>Automatic</option><option>Manual</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label fw-bold">Image URL</label>
|
|
<input type="text" name="image" class="form-control rounded-3" required placeholder="Paste an image link here">
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label fw-bold">Description</label>
|
|
<textarea name="description" class="form-control rounded-3" rows="5" placeholder="Tell us more about the car condition, options, etc."></textarea>
|
|
</div>
|
|
<div class="col-12 mt-4">
|
|
<button type="submit" class="btn btn-primary btn-lg w-100 rounded-3 py-3">Submit Listing for Review</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include '../includes/footer.php'; ?>
|