PHP 没有传递要插入的变量?

PHP Not Passing Variables to Insert?

知道为什么这不会将 PO、AP 和 Facility 传递给 SQL 插入语句吗?我用文字值进行了测试,当我 运行 查询以查找 values.l

时,它会以其他方式工作

我很茫然,求助?

<?php
if (! empty($_FILES)) {
    $imagePath = isset($_FILES["file"]["name"]) ? $_FILES["file"]["name"] : "Undefined";
    $targetPath = "uploads/";
    $imagePath = $targetPath . $imagePath;
    $tempFile = $_FILES['file']['tmp_name'];

    $targetFile = $targetPath . $_FILES['file']['name'];

    if (move_uploaded_file($tempFile, $targetFile)) {
        echo "true";
    } else {
        echo "false";
    }
}
$po = $_GET["po"];
$ap = $_GET["ap"];
$facility = $_GET["facility"];

if (! empty($_GET["action"]) && $_GET["action"] == "save") {

    require_once ("db.php");

    print $sql = "INSERT INTO images_info (image_path, po, ap, facility) VALUES ('" . $imagePath . "', '" . $_GET["po"] . "', '" . $ap . "', '" . $facility . "')";

    mysqli_query($conn, $sql);
    $current_id = mysqli_insert_id($conn);
}
?>
<html>
<head>
<title>Add New Image</title>
<link rel="stylesheet" type="text/css" href="css/styles.css" />

<link rel="stylesheet" type="text/css" href="dropzone/dropzone.css" />
<?php echo "PO#: ".$po."<br />" ?>
<?php echo "AP#: ".$ap."<br />"  ?>
<?php echo "Facility#: ".$facility."<br />"  ?>
<script type="text/javascript" src="dropzone/dropzone.js"></script>
</head>
<body>
    <form name="frmImage" action="image-add.php?action=save"
        class="dropzone"></form>
    <div class="btn-menu">
        <a href="index.php" class="link">Back to List</a>
    </div>
</body>
</html>

我在您的表单中没有看到任何输入字段。看看 this comment on an Dropzone.js with PHP example。要点本身应该可以帮助您解决问题。

所以表格应该是这样的:

<form name="frmImage" action="image-add.php?action=save" class="dropzone">
    <input type="hidden" name="po" value="<?php echo $po; ?>">
    <input type="hidden" name="ap" value="<?php echo $ap; ?>">
    <input type="hidden" name="facility" value="<?php echo $facility; ?>">
</form>

由于您似乎没有在表单中使用提交按钮,这里有一个示例片段,用于在 post 请求中将表单数据与文件一起传递:

myDropzone.on("sending", function(file, xhr, formData) {
    poValue = document.querySelector("input[name=po]").value;
    formData.append("po", poValue ); 
    apValue = document.querySelector("input[name=ap]").value;
    formData.append("ap", apValue ); 
    facilityValue = document.querySelector("input[name=facility]").value;
    formData.append("facility", facilityValue ); 
});

您必须根据自己的需要进行调整。