From 08d15c9253f718fb5fc9347d7c9e276cf699a0ec Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sun, 24 Jul 2022 10:43:54 +0100 Subject: [PATCH] Prepared sql for pain --- css/image.css | 10 ++++++---- css/master.css | 4 ++-- css/nav.css | 2 +- edit.php | 28 ++++++++++++++-------------- image.php | 25 ++++++++++++++++--------- index.php | 37 ++++++++++++++++--------------------- ui/conn.php | 2 +- upload.php | 20 +++++++++----------- 8 files changed, 65 insertions(+), 63 deletions(-) diff --git a/css/image.css b/css/image.css index afd348f..45406c6 100644 --- a/css/image.css +++ b/css/image.css @@ -12,7 +12,7 @@ @media (max-width: 600px) { .image-container { - height: 40vh; + height: 35vh; } } @@ -30,7 +30,7 @@ } .image-description { - margin: 0 0 2rem; padding: 0.5rem;; + margin: 0 0 2rem; padding: 0.5rem; background-color: var(--bg); color: var(--fg); @@ -42,10 +42,12 @@ } .image-detail { - margin: 0 0 2rem; padding: 0.5rem;; + margin: 0 0 2rem; padding: 0.5rem; background-color: var(--bg); color: var(--fg); + word-wrap: break-word; + border: 0.2rem solid var(--green); outline: 0.5rem solid var(--bg); @@ -54,7 +56,7 @@ } .danger-zone { - margin: 0 0 2rem; padding: 0.5rem;; + margin: 0 0 2rem; padding: 0.5rem; background-color: var(--bg); color: var(--fg); diff --git a/css/master.css b/css/master.css index 6f3bbe6..0c396b6 100644 --- a/css/master.css +++ b/css/master.css @@ -117,7 +117,7 @@ form * { align-items: center; vertical-align: middle; - text-decoration: underline; + text-decoration: none; border: none; border-radius: var(--rad); @@ -138,7 +138,7 @@ a.btn { .svg { margin: 0 0.2rem 0.1rem 0; - width: 18px; height: 18px; + width: 19px; height: 18px; vertical-align: middle; diff --git a/css/nav.css b/css/nav.css index d838898..737bbd6 100644 --- a/css/nav.css +++ b/css/nav.css @@ -21,7 +21,7 @@ nav h3 { margin: 0; } nav hr { - margin: 0.5rem 0; padding: 0; + margin: 0.5rem 0.2rem; padding: 0; opacity: 0; } diff --git a/edit.php b/edit.php index 79762f8..401b8f0 100644 --- a/edit.php +++ b/edit.php @@ -10,18 +10,16 @@ - +

Modify Information

-

Make sure that the id of the image is correct!

+

This is a dangerous place to step foot into... tread carefully.

- Update information"; ?> + Update information"; ?>
+ No description/alt, pls give

"; - } else { - // echo "

Please enter information

"; } ?>
- prepare("UPDATE swag_table SET alt=? WHERE id=?"); + $sql->bind_param("si", $alt, $id); - if (mysqli_query($conn, $sql)) { + $alt = $_POST['alt']; + $id = $_POST['id']; + + if ($sql->execute()) { //header("Location:edit.php?r=success"); - header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$_POST['update']."&update=success"); + header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$_POST['id']."&update=success"); } else { header("Location:edit.php?r=fail"); } @@ -57,7 +58,6 @@ } ?> - diff --git a/image.php b/image.php index 4088d85..fdb352f 100644 --- a/image.php +++ b/image.php @@ -14,32 +14,38 @@ include("ui/header.php"); include_once("ui/conn.php"); + + // Update toast + if ($_GET["update"] == "success") { + echo "

Information updated

"; + } + + // Get image ID // Getting all image info from table $get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id']; $image_results = mysqli_query($conn, $get_image); $image = mysqli_fetch_assoc($image_results); - // Image has been modified successfully - if ($_GET["update"] == "success") { - echo "

Information updated

"; - } - // Check if ID of image in URL if (!isset($_GET['id'])) { - // No ID + // No ID toast echo "

No ID present

"; + // Replacement "no image" image and description $image_path = "assets/no_image.png"; $image_alt = "No image could be found, sowwy"; + } elseif (empty($image['imagename'])) { - // proposed ID not avalible + // ID not avalible toast echo "

Could not find image with ID: ".$_GET['id']."

"; + // Replacement "no image" image and description $image_path = "assets/no_image.png"; $image_alt = "No image could be found, sowwy"; + } else { - // Image avalible + // Display image $image_path = "images/".$image['imagename']; $image_alt = $image['alt']; } @@ -95,10 +101,11 @@ // Check if query is set if (isset($_POST['delete'])) { // Try deleting image - if(unlink("images/".$image['imagename'])) { + if(unlink("images/".$image['imagename']) && unlink("images/thumbnails/".$image['imagename'])) { // If deleted, delete from Table $image_delete_request = "DELETE FROM swag_table WHERE id =".$image['id']; $image_delete = mysqli_query($conn,$image_delete_request); + if ($image_delete) { // Deleted image header("Location:index.php?del=true&id=".$image['id']); diff --git a/index.php b/index.php index f4c3fdb..ebeb601 100644 --- a/index.php +++ b/index.php @@ -10,9 +10,10 @@ - - Successfully deleted image: ".$_GET['id']."

"; } @@ -23,30 +24,24 @@

Fluffy's test website on uploading images to a database!

- Image ".$_GET['d']." has been modified, view status here

"; - } - ?> "; } ?> diff --git a/ui/conn.php b/ui/conn.php index 3a63d54..79bd767 100644 --- a/ui/conn.php +++ b/ui/conn.php @@ -2,7 +2,7 @@ // Attempt database connection $conn = mysqli_connect("localhost", "uwu", "password", "swag"); // If connecton failed, notify user -if (!$conn) { +if ($conn->connect_error) { echo "

Could not connect to database

"; } ?> diff --git a/upload.php b/upload.php index ca16884..9b7e7b0 100644 --- a/upload.php +++ b/upload.php @@ -17,8 +17,9 @@
- +
+ No file lol

"; - } else { - // echo "

Select an image to upload

"; } ?> @@ -38,10 +37,9 @@ prepare("INSERT INTO swag_table (imagename, alt) VALUES (?, ?)"); + $sql->bind_param("ss", $image_name, $get_alt_text); // Uploading image to Table - mysqli_query($conn, $sql); - + $sql->execute(); // Checking if image uploaded if (move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) {