Here is my code:
<?php
    include ('navbar.php');
?>
<form class = "container m-5" method = "POST" action = "upload.php" encytype = "multipart/form-data">
<input class = "form-control w-25" type = "file" name = "file">
<button class = "btn" type = "submit" name = "Upload">Upload</button>
</form>
<?php
include'connect.php';
$statusMsg = '';
// File upload path
$targetDir = "image";
$fileName = $_FILES["file"]["name"];
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){
    // Allow certain file formats
    $allowTypes = array('jpg','png','jpeg','pdf');
    if(in_array($fileType, $allowTypes)){
        // Upload file to server
        if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
            // Insert image file name into database
            $insert = $db->query("INSERT into userid (FileName) VALUES ('".$fileName."'");
            if($insert){
                $statusMsg = "The file ".$fileName. " has been uploaded successfully.";
            }else{
                $statusMsg = "File upload failed, please try again.";
            } 
        }else{
            $statusMsg = "Sorry, there was an error uploading your file.";
        }
    }else{
        $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.';
    }
}else{
    $statusMsg = 'Please select a file to upload.'; 
}
// Display status message
echo $statusMsg;
?>
The only message that I received is this
Notice: Undefined index: file in C:\xampp\htdocs\Project\upload.php on line 15 Please select a file to upload.
And nothing shows in my database
 
     
    