<?php
require_once 'auth_check.php';
require_once '../config/database.php';
// Get business ID from URL
if (!isset($_GET['id'])) {
die("No business ID provided.");
}
$business_id = (int) $_GET['id'];
// Fetch business record
$stmt = $pdo->prepare("SELECT * FROM businesses WHERE id = ?");
$stmt->execute([$business_id]);
$business = $stmt->fetch();
if (!$business) {
die("Business not found.");
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'];
$contact_name = $_POST['contact_name'];
$status = $_POST['status'];
$update = $pdo->prepare("
UPDATE businesses
SET name = ?, contact_name = ?, status = ?, updated_at = NOW()
WHERE id = ?
");
$update->execute([$name, $contact_name, $status, $business_id]);
echo "<p style='color:green;'>Business updated successfully.</p>";
// Refresh business data
$stmt->execute([$business_id]);
$business = $stmt->fetch();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Business</title>
</head>
<body>
<h2>Edit Business</h2>
<p><a href="business_list.php">Back to Business List</a></p>
<form method="POST">
<label>Business Name:</label><br>
<input type="text" name="name" value="<?php echo htmlspecialchars($business['name']); ?>" required><br><br>
<label>Contact Name:</label><br>
<input type="text" name="contact_name" value="<?php echo htmlspecialchars($business['contact_name']); ?>" required><br><br>
<label>Status:</label><br>
<select name="status">
<option value="pending" <?php if ($business['status']=='pending') echo 'selected'; ?>>Pending</option>
<option value="approved" <?php if ($business['status']=='approved') echo 'selected'; ?>>Approved</option>
<option value="rejected" <?php if ($business['status']=='rejected') echo 'selected'; ?>>Rejected</option>
<option value="suspended" <?php if ($business['status']=='suspended') echo 'selected'; ?>>Suspended</option>
</select><br><br>
<button type="submit">Save Changes</button>
</form>
</body>
</html>