0

I just want some help from you guys. I want to upload an image file to database using and MYSQL. I'm having trouble on how to do it. I need your help. my code is example of how i want to upload the image. but I cant understand on how to do its. i have this 2 warnings when i try to execute the code

Warning: Undefined array key "image" in C:\xampp\htdocs\home-form\admin\create.php on line 52

Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\home-form\admin\create.php on line 52

<?php

require_once "config.php";

$image = "";
$image_err = "";

if($_SERVER["REQUEST_METHOD"] == "POST") {

   $input_image = trim($_FILES["image"]['name']);
   if(empty($input_image)) {

      $image_err = "Please enter skill.";     
   } else {

      $image = $input_image;
   }

   if(empty($image_err)) {

      $sql = "INSERT INTO employees (image) VALUES (?)";
        
      if($stmt = mysqli_prepare($conn, $sql)) {

        mysqli_stmt_bind_param($stmt, "b", $param_image);

        $param_image = $image;

        if(mysqli_stmt_execute($stmt)) {

            header("location: dashboard.php");
            exit();
        } else {

            echo "Oops! Something went wrong. Please try again later.";
        }
      }
      mysqli_stmt_close($stmt);
    }
    mysqli_close($conn);
  }
?>
4
  • Replace $input_image = trim($_FILES["image"]['name']); if(empty($input_image)) { $image_err = "Please enter skill."; } with if(!isset($_FILES["image"])) { $image_err = "Please enter skill."; } Commented Jan 12, 2022 at 6:47
  • not working bro Commented Jan 12, 2022 at 6:53
  • Did you set the correct enctype for file uploads on your form? Commented Jan 12, 2022 at 7:46
  • i dont have enctype in my form. i have 5 inputs. 4 text and 1 image Commented Jan 12, 2022 at 7:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.