如何在特定行中上传 MYSQL 中的照片或文件?

How to upload a Photo or a file in MYSQL in a specific row?

我有一个表格,让我的用户输入他的电子邮件并上传照片。假设我的用户在我的数据库中已经有一个现有的电子邮件,他想上传一张他的照片。现在的问题是如何去做? 如何获取我的 input type = "email" 的值并将其用于我的查询,如下所示:

$query = "insert into user (Photo) values ('".$file."') where email = "$_GET['email']"";

我尝试了这个查询,但它不起作用我该怎么办?

编辑:这是我的全部代码

<form class = "container" method = "POST" action = "upload.php" enctype = "multipart/form-data">
                <input name = "mang" type = "email" class = "form-control w-75" placeholder="Put Your EMAIL here">
                <center> <input class = "form-control w-75" type = "file" name = "photo">
                <button class = "btn" type = "submit" name = "Upload">Upload</button>
                </form>
<?php
include'connect.php';
// File upload path

if(isset($_POST["Upload"]) && !empty($_FILES["photo"]["name"])){
    $targetDir = "image/";
    $fileName = $_FILES["photo"]["name"];
    $targetFilePath = $targetDir . $fileName;
    $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
    // Allow certain file formats
    $allowTypes = array('jpg','png','jpeg','pdf');
    if(in_array($fileType, $allowTypes)){
        // Upload file to server
        if(move_uploaded_file($_FILES["photo"]["tmp_name"], $targetFilePath)){
            // Insert image file name into database
            $insert =$connect->query("insert into user (Photo) values ('".$file."') where email = "$_GET['email']"");
            
            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
print "<p>" .$statusMsg. "</p>";
?>
<div>

</div>

您的表格有误,您使用了方法 POST 并使用 GET 方法获取值。所以使用 $_POST 变量来获取值 echo $_POST['email'];

在您的情况下,您的电子邮件字段的名称为 mang,因此请使用 $_POST['mang']; 获取电子邮件字段值。