0

I am trying to upload the name of the selected file to the database. For this I made a HTML page . The code of HTML page is

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Photo Input</title>
</head>

<body>
    <form action="input-photo.php" method="POST" enctype="multipart/form-data" >

        <h3>Insert a photo</h3>
        <input type="file" name="image" id="1"  >
        <br>
        <br>
        <input type="submit" name="upload" value="upload image">
    </form>
    
</body>
</html>

The action of this form in HTML is in input-photo.php file . The code of this php file is

<?php
    $server = "localhost";
    $username ="root";
    $password = "";
    $conn = mysqli_connect($server,$username,$password,"form");
    if(isset($_POST['upload']))
    {
        $name = $_FILES['image']['name'];
        echo $name;
    }
?>

But when i run this segment of code it shows two warnings:-
Warning: Undefined array key "image"
Warning: Trying to access array offset on value of type null

The warning is shown for the .php file where $_FILES is used. It says Undefined array key "image"
I dont know how to resolve this.

6
  • When do you see this error? After submitting the form? When opening the page directly? Commented Oct 21, 2021 at 18:52
  • When i click the upload image then the error is shown. Commented Oct 21, 2021 at 18:56
  • Do any of the answers here help? stackoverflow.com/questions/19027992/… Commented Oct 21, 2021 at 18:58
  • 1
    It looks like it should work. You have selected a file? Try var_dump($_FILES); Commented Oct 21, 2021 at 19:09
  • 1
    Make sure to check your file_uploads=On in php.ini file Commented Oct 21, 2021 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.