/
home
/
u839856410
/
domains
/
frajuuconnect.online
/
public_html
/
Upload File
HOME
<?php session_start(); include 'db_connection.php'; if(!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true){ header("Location: admin_login.php"); exit; } if(!isset($_GET['table'], $_GET['id'])){ header("Location: manage_listings.php"); exit; } $table = $_GET['table']; $id = $_GET['id']; $error = ''; $success = ''; // Fetch listing $res = $conn->query("SELECT * FROM $table WHERE id='$id'"); if($res->num_rows != 1){ header("Location: manage_listings.php"); exit; } $listing = $res->fetch_assoc(); // Update if($_SERVER['REQUEST_METHOD'] === 'POST'){ $title = $conn->real_escape_string($_POST['title']); $location = $conn->real_escape_string($_POST['location']); $price = $conn->real_escape_string($_POST['price']); $status = $conn->real_escape_string($_POST['status']); $update = $conn->query("UPDATE $table SET title='$title', location='$location', price='$price', status='$status' WHERE id='$id'"); if($update){ $success = "Listing updated successfully!"; $listing = $conn->query("SELECT * FROM $table WHERE id='$id'")->fetch_assoc(); } else { $error = "Error updating listing: ".$conn->error; } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Edit Listing</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container my-5"> <h2>Edit Listing (<?php echo htmlspecialchars($table); ?>)</h2> <a href="manage_listings.php" class="btn btn-secondary mb-3">Back to Listings</a> <?php if($error) echo "<div class='alert alert-danger'>$error</div>"; ?> <?php if($success) echo "<div class='alert alert-success'>$success</div>"; ?> <form method="POST"> <div class="mb-3"> <label>Title</label> <input type="text" class="form-control" name="title" value="<?php echo htmlspecialchars($listing['title'] ?? $listing['name']); ?>" required> </div> <div class="mb-3"> <label>Location</label> <input type="text" class="form-control" name="location" value="<?php echo htmlspecialchars($listing['location']); ?>" required> </div> <div class="mb-3"> <label>Price / Rent</label> <input type="number" class="form-control" name="price" value="<?php echo htmlspecialchars($listing['price'] ?? $listing['rent']); ?>" required> </div> <div class="mb-3"> <label>Status</label> <select class="form-select" name="status" required> <option value="available" <?php if($listing['status']=='available') echo 'selected'; ?>>Available</option> <option value="sold" <?php if($listing['status']=='sold') echo 'selected'; ?>>Sold</option> <option value="rented" <?php if($listing['status']=='rented') echo 'selected'; ?>>Rented</option> </select> </div> <button class="btn btn-primary">Update Listing</button> </form> </div> </body> </html>