Editando: add_casestudy.php
<?php session_start(); include("includes/config.php"); if(isset($_POST['add_case'])){ $title = $_POST['title']; $location = $_POST['location']; $description = $_POST['description']; $photo = $_FILES['photo']['name']; $allowed_image_extensions = array('gif','png','jpg','jpeg','webp','WEBP' ,'jfif'); $photo_filename = $_FILES['photo']['name']; $photo_file_extension = pathinfo($photo_filename, PATHINFO_EXTENSION); if(!in_array($photo_file_extension, $allowed_image_extensions)){ $_SESSION['status'] = "The image file is not allowed. Please upload an image."; header('Location: casestudy.php'); exit; } else { $query = "INSERT INTO casestudies (title, location, description, photo ) VALUES ('$title', '$location', '$description', '$photo')"; $query_run = mysqli_query($conn, $query); if($query_run){ move_uploaded_file($_FILES["photo"]["tmp_name"], "casestudy/".$_FILES["photo"]["name"]); $_SESSION['status'] = "Uploaded Successfully"; echo "<script>window.location.href='view-casestudy.php';</script>"; // header('Location: view-category.php'); exit; } else { $_SESSION['status'] = "Not Uploaded "; echo "<script>window.location.href='view-casestudy.php';</script>"; // header('Location: category.php'); exit; } } } // update if(isset($_POST['update_case'])){ $id = $_POST['id']; $title = $_POST['title']; $location = $_POST['location']; $description = $_POST['description']; $old_photo = $_POST['image_old']; $update_photo_filename = $_FILES["photo"]["name"] ? $_FILES["photo"]["name"] : $old_photo; $query = "UPDATE casestudies SET title='$title', location='$location', description='$description', photo='$update_photo_filename' WHERE id ='$id' "; $query_run = mysqli_query($conn, $query); if($query_run){ if($_FILES["photo"]["name"] !='' && $_FILES["photo"]["name"] != $old_photo){ move_uploaded_file($_FILES["photo"]["tmp_name"], "casestudy/".$_FILES["photo"]["name"]); unlink("casestudy/". $old_photo); } $_SESSION['status'] = "Updated Successfully"; echo "<script>window.location.href='view-casestudy.php';</script>"; // header('Location: view-category.php'); } else { $_SESSION['status'] = "Not Updated "; echo "<script>window.location.href='view-casestudy.php';</script>"; // header('Location: view-category.php'); } } // delete if(isset($_POST['delete_case'])){ $id = $_POST['delete_id']; $photo = $_POST['del_case']; $query = "DELETE FROM casestudies WHERE id = '$id'"; $query_run = mysqli_query($conn, $query); if($query_run){ $_SESSION['status'] = "Deleted Successfully"; echo "<script>window.location.href='view-casestudy.php';</script>"; } else { $_SESSION['status'] = "Not Deleted Successfully"; echo "<script>window.location.href='view-casestudy.php';</script>"; } }
Cancelar
Kerym Chaeceran