【发布时间】:2016-03-23 13:23:57
【问题描述】:
最近我创建了一个表单,该表单连接到 2 个表,其中 1 个包含文件,其他包含项目,同时提交表单时您可以上传文件以及 1 个以上,因为我使用的上传器是 dropzone.js,并且 ebveryone 知道 dropzone 提交当有人上传文件并且不提交表单时,文件具有不同的表单 id 冲突假设我上传文件,但后来我决定不提交表单 这里发生的情况是,当下一个用户来填写并提交时,文件将保存在数据库中表格连同上传文件 这里发生的是分配给以前文件的 id 将与当前文件匹配 我相信通过查看代码你会明白我做了什么和我需要什么 我不知道如何解释但有时提交的文件包含错误的项目
dropzone上传代码
<?php
require_once("../../../includes/connection.php");
if(!empty($_FILES)){
$targetDir = "../../uploads/";
$fileName = $_FILES['file']['name'];
$targetFile = $targetDir.$fileName;
//Getting ID to match with the submitted project form details
$query_get = mysqli_query($connection, "SELECT * FROM projects ORDER BY proj_id DESC LIMIT 1");
while($id = mysqli_fetch_assoc($query_get)) {
$uid = $id["proj_id"];
}
$uid1 = $uid+1;//This id will becomes imaginary now as if the files and form were submitting at a time the i would have used mysqli_insert_id but in this case i cannot use
if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
//insert file information into db table
$conn = mysqli_query($connection, "INSERT INTO files (proj_id, file_name, uploaded) VALUES('$uid1', '".$fileName."','".date("Y-m-d H:i:s")."')");
}
}
?>
这是我的 startproject 表单提交功能
function add_project($connect) {
$fname = $_POST["first_name"];
$lname = $_POST["last_name"];
$proj_name = $_POST["proj_name"];
$email = $_POST["email"];
$end_date = $_POST["end_date"];
$skype = $_POST["skype"];
$company_url = $_POST["url"];
$detail1 = mysqli_real_escape_string($connect, $_POST["details1"]);
$detail2 = mysqli_real_escape_string($connect, $_POST["details2"]);
$detail3 = mysqli_real_escape_string($connect, $_POST["details3"]);
$upload_date = date("F-d-Y");
$query2 = "INSERT INTO projects (first_name, last_name, proj_name, end_date, detail1, detail2, detail3, email, uploaded_date, skype_name, company_url, status) VALUES ('$fname', '$lname', '$proj_name', '$end_date', '$detail1', '$detail2', '$detail3', '$email', '$upload_date', '$skype', '$company_url', 'submit')";
$confirm2 = mysqli_query($connect, $query2);
}
谢谢,我相信这是一个常见的问题,但我希望有人能理解并帮助我
【问题讨论】: