prepare($sql);
$stmt->bindParam(':vendor_id', $vendor_id, PDO::PARAM_INT);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':description', $description, PDO::PARAM_STR);
$stmt->bindParam(':price', $price, PDO::PARAM_STR);
$stmt->bindParam(':image_url', $image_url, PDO::PARAM_STR);
if ($stmt->execute()) {
$message = "
Product added successfully!
";
} else {
$message = "Error adding product.
";
}
} catch (PDOException $e) {
$message = "Database error: " . $e->getMessage() . "
";
}
} else {
$message = "Please fill in all fields.
";
}
}
// Fetch vendor's products
$products = [];
try {
$sql = "SELECT * FROM products WHERE vendor_id = :vendor_id ORDER BY created_at DESC";
$stmt = db()->prepare($sql);
$stmt->bindParam(':vendor_id', $vendor_id, PDO::PARAM_INT);
$stmt->execute();
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$message .= "Error fetching products: " . $e->getMessage() . "
";
}
?>
Vendor Dashboard
Welcome, !
| Image |
Name |
Price |
Date Added |
| You haven't added any products yet. |
![<?php echo htmlspecialchars($product['name']); ?>](<?php echo htmlspecialchars($product['image_url']); ?>) |
|
$ |
|