-1

HTML:

    <form  action="submit.php" method="POST" >
 <div class="file-input">
              
              <input type="file" class="attestat" id="attestat" name="attestat" accept="application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, image/*" multiple="multiple">
              <span class="file-name">Выберите файл</span>
            </div>
</form>

and PHP:

<?php
$servername = "localhost";
$username = "root";
$password = "Youshit21";
$dbname = "medacc";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}



  $filetmpname = $_FILES["attestat"]["tmp_name"];

  $id = uniqid('user_');

  $sql = "INSERT INTO medacc.spaco(id,filo) VALUES ('$id', '$filetmpname')";
  if ($conn->query($sql) === TRUE) {
    echo "File uploaded successfully.";
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }





$conn->close();

?>

and its always showing this error: Warning: Undefined array key "attestat" in D:\localhost\acceptance form\submit.php on line 14

Warning: Trying to access array offset on value of type null in D:\localhost\acceptance form\submit.php on line 14

the code inserts file to mysql table , but its simply does not see the file input and doesnt change no matter what i doyour text

7
  • 3
    php.net/manual/en/features.file-upload.post-method.php ... missing enctype Commented May 8, 2023 at 11:27
  • can you tell in more detail? Commented May 8, 2023 at 11:31
  • You did not add multipart/form-data in the form tag. Commented May 8, 2023 at 11:31
  • 4
    Also, be warned that your INSERT query is highly vulnerable for SQL injection. Have a look at prepared statements to avoid getting hacked Commented May 8, 2023 at 11:31
  • 2
    If you want to handle file uploads, enctype="multipart/form-data" is a must! Commented May 8, 2023 at 11:32

2 Answers 2

0

you are not submitting the form i guess .. moreover since you are accepting multiple files it would require something like this

<form action="submit.php" method="POST" enctype="multipart/form-data">
  <div class="file-input">
    <input type="file" class="attestat" id="attestat" name="attestat[]" accept="application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, image/*" multiple="multiple">
    <span class="file-name">Выберите файл</span>
  </div>
  <button type="submit">Submit</button>
</form>
Sign up to request clarification or add additional context in comments.

Comments

-2

please add this attribute in form tag enctype="multipart/form-data" to solve your issue.
like this:

 <form  action="submit.php" method="POST" enctype="multipart/form-data" >

for more details you can follow this link.

1 Comment

This has already been answered here stackoverflow.com/questions/19027992/… Please do not add duplicate answers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.