📁 File Manager
Editing:
/home/wedigitalindia/public_html/admin/edit_service_location_page.php
<?php include("connection.php"); include("header.php"); $loc_id = isset($_GET['loc_id']) ? intval($_GET['loc_id']) : 0; function generateSlug($string) { $slug = preg_replace('/[^A-Za-z0-9-]+/', '-', strtolower($string)); return trim($slug, '-'); } /* Fetch Existing Data */ $getData = mysqli_query( $con, "SELECT * FROM tbl_location_pages WHERE loc_id='$loc_id'" ); $row = mysqli_fetch_assoc($getData); if (!$row) { die("Record not found"); } /* Update */ if (isset($_POST['update'])) { $category_id = intval($_POST['category_id']); $location_name = mysqli_real_escape_string($con, $_POST['location_name']); $description = mysqli_real_escape_string($con, $_POST['description']); $status = intval($_POST['status']); $inputSlug = trim($_POST['slug']); if (empty($inputSlug)) { $slug = generateSlug($location_name); } else { $slug = generateSlug($inputSlug); } /* Check duplicate slug except current record */ $checkSlug = mysqli_query( $con, "SELECT COUNT(*) as total FROM tbl_location_pages WHERE slug='$slug' AND loc_id != '$loc_id'" ); $slugRow = mysqli_fetch_assoc($checkSlug); if ($slugRow['total'] > 0) { $slug .= '-' . time(); } /* Image Handling */ $Image = $row['image']; if ( isset($_FILES['Image']) && $_FILES['Image']['error'] == 0 && !empty($_FILES['Image']['name']) ) { $originalName = $_FILES['Image']['name']; $tmpName = $_FILES['Image']['tmp_name']; $extension = strtolower( pathinfo($originalName, PATHINFO_EXTENSION) ); $newImage = 'loc_' . time() . '_' . uniqid() . '.' . $extension; $uploadPath = "./assets/images/location/" . $newImage; if (move_uploaded_file($tmpName, $uploadPath)) { if ( !empty($row['image']) && file_exists("./assets/images/location/" . $row['image']) ) { unlink("./assets/images/location/" . $row['image']); } $Image = $newImage; } } $update = mysqli_query( $con, "UPDATE tbl_location_pages SET category_id='$category_id', location_name='$location_name', slug='$slug', description='$description', image='$Image', status='$status' WHERE loc_id='$loc_id'" ); if ($update) { echo " <script> alert('Location Page Updated Successfully'); window.location='view_service_location_pages.php'; </script>"; exit; } else { echo mysqli_error($con); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Edit Service Location</title> <link rel="shortcut icon" href="./assets/logo/fav.png"> <link href="assets/libs/dropzone/dropzone.css" rel="stylesheet"> <link href="assets/css/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/icons.min.css" rel="stylesheet"> <link href="assets/css/app.min.css" rel="stylesheet"> <style> input[name='Image'] { display: none; } #upload { cursor: pointer; } .filepath { display: block; margin-top: 15px; } img[alt='img'] { width: 150px; border-radius: 10px; } </style> </head> <body data-sidebar="dark"> <div id="layout-wrapper"> <div class="page-content" style="width:80%;margin-left:260px;"> <div class="container"> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-body"> <h4 class="mb-4"> Edit Service Location </h4> <form method="POST" enctype="multipart/form-data"> <div class="dropzone"> <div class="fallback"> <input type="file" name="Image" id="imageInput"> </div> <div class="dz-message needsclick" id="upload"> <div class="mb-3"> <i class="display-4 text-muted bx bxs-cloud-upload"></i> </div> <h4>Drop files here or click to upload.</h4> </div> </div> <div class="filepath"> <img id="previewImg" src="./assets/images/location/<?php echo $row['image']; ?>" alt="img"> <br><br> <span id="filename"> <?php echo $row['image']; ?> </span> </div> <br> <div class="row"> <div class="col-lg-3"> <label>Select Service</label> <select name="category_id" class="form-control"> <?php $q = mysqli_query( $con, "SELECT * FROM tbl_top_category" ); while ($cat = mysqli_fetch_assoc($q)) { ?> <option value="<?php echo $cat['t_id']; ?>" <?php if ($cat['t_id'] == $row['category_id']) { echo "selected"; } ?>> <?php echo $cat['cat_name']; ?> </option> <?php } ?> </select> </div> <div class="col-lg-5"> <label>Location Name</label> <input type="text" name="location_name" id="location_name" class="form-control" value="<?php echo $row['location_name']; ?>" onkeyup="generateSlug()"> </div> <div class="col-lg-4"> <label>Slug</label> <input type="text" name="slug" id="slug" class="form-control" value="<?php echo $row['slug']; ?>"> </div> </div> <br> <label>Description</label> <textarea name="description" id="description"><?php echo htmlspecialchars($row['description']); ?></textarea> <br> <div class="col-lg-3"> <label>Status</label> <select name="status" class="form-control"> <option value="1" <?php if($row['status']==1) echo "selected"; ?>> Active </option> <option value="0" <?php if($row['status']==0) echo "selected"; ?>> Inactive </option> </select> </div> <br> <div class="text-center mt-4"> <button type="submit" name="update" class="btn btn-primary"> Update </button> <a href="view_service_location_pages.php" class="btn btn-danger"> View Data </a> </div> </form> </div> </div> </div> </div> </div> </div> </div> <script src="assets/libs/jquery/jquery.min.js"></script> <script src="assets/js/app.js"></script> <script src="./ck editor/ckeditor.js"></script> <script> CKEDITOR.replace('description'); </script> <script> const imgInput = document.querySelector("input[name='Image']"); const uploadBox = document.getElementById('upload'); const previewImg = document.getElementById('previewImg'); const filename = document.getElementById('filename'); uploadBox.onclick = () => { imgInput.click(); }; imgInput.onchange = () => { if(imgInput.files.length > 0) { const file = imgInput.files[0]; previewImg.src = URL.createObjectURL(file); filename.innerHTML = file.name; } }; function generateSlug() { let location = document.getElementById( "location_name" ).value; let slug = location.toLowerCase() .replace(/[^a-z0-9\s-]/g,'') .replace(/\s+/g,'-') .replace(/-+/g,'-') .trim(); document.getElementById('slug').value = slug; } </script> </body> </html>
Save
Cancel