prepare("SELECT * FROM items WHERE id = ? AND owner_id = ?"); $stmt->execute([$item_id, $vendor_id]); $item = $stmt->fetch(); if (!$item) { $errors[] = "Item not found or you don't have permission to edit it."; $item_id = null; // Invalidate item_id if not found or unauthorized } } else { $errors[] = "No item ID provided."; } // Handle form submission for updating the item if ($_SERVER["REQUEST_METHOD"] == "POST" && $item_id) { $name = trim($_POST['name']); $description = trim($_POST['description']); $price_per_day = trim($_POST['price_per_day']); $location = trim($_POST['location']); $image_url = trim($_POST['image_url']); if (empty($name)) { $errors[] = "Item name is required."; } if (empty($price_per_day) || !is_numeric($price_per_day)) { $errors[] = "A valid price is required."; } if (empty($location)) { $errors[] = "Location is required."; } if (empty($errors)) { try { $sql = "UPDATE items SET name = :name, description = :description, price_per_day = :price_per_day, location = :location, image_url = :image_url WHERE id = :id AND owner_id = :owner_id"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':name' => $name, ':description' => $description, ':price_per_day' => $price_per_day, ':location' => $location, ':image_url' => $image_url, ':id' => $item_id, ':owner_id' => $vendor_id ]); $success_message = "Item updated successfully!"; // Refresh item data after update $stmt = $pdo->prepare("SELECT * FROM items WHERE id = ? AND owner_id = ?"); $stmt->execute([$item_id, $vendor_id]); $item = $stmt->fetch(); } catch (PDOException $e) { $errors[] = "Database error: " . $e->getMessage(); } } } ?> Edit Item - RentEase

Edit Rental Item

Cancel

Unable to load item for editing.

Back to My Listings