gpt4 book ai didi

javascript - JS中的下拉列表并想使用PHP保存在数据库中。我不知道,可以帮助我吗?

转载 作者:行者123 更新时间:2023-12-03 04:16:18 25 4
gpt4 key购买 nike

我想上传 pdf 文件,但需要选择属于哪个 pdf 文件。问题是,当我做出一个严重的选择,然后基于第一个选项有第二个选项。第二个选项是使用js,我不知道如何将其发布到数据库中。

这是Upload.php

 <div class="graph-form agile_info_shadow">
<h3 class="w3_inner_tittle two">Upload File Here </h3>
<div class="form-body">
<form action="UploadProcess.php" method="post" enctype="multipart/form-data">
<!-- <div class="form-group"> <label for="exampleInputEmail1">Name of Folder</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email"> </div> -->
<div class="form-group"> <label for="chooseOption">Choose >> </label>

<select name="main" id="main" onchange="ChangeList();setValue()" required>
<option value="">-------------- OPTION --------------</option>
<option value="IMS">Integrated Management System</option>
<option value="PM">Personnel Manual</option>
<option value="NP">Nursing Procedure</option>
<option value="SQM">Service Quality Management</option>
<option value="IC">Infection Control</option>
<option value="TRM">Training Manual</option>
</select>


<div id="div1"></div>

</div>
<div class="form-group"> <label for="chooseDepartment">Choose Department >> </label>

<select name="department" id="department" onChange="setValue();" required>

<script>

var department = {};
department['IMS'] = ['Accident & Emergency', 'Admin', 'Audiology','Billing', 'Critical Care Unit', 'Diagnosis', 'Dietition', 'Finance','General Ward', 'Haemodialysis', 'Information Technology', 'Medical Record', 'Marketing', 'Nursing Administrations', 'O&G ', 'Operation Theatre','Pharmacy', 'Physiotheraphy', 'Public Relation', 'Purchasing', 'Quality', 'Surgical', 'Talent Management'];
department['PM'] = ['Manual'];
department['NP'] = ['Volume 1', 'Volume 2', 'Volume 3'];
department['SQM'] = ['Form', 'Manual'];
department['IC'] = ['Manual', 'MOH Infectious Guideline'];
department['TRM'] = ['Pharmacy Services', 'Hospital Engineering Services', 'Laboratory Services(Lablink)','Medical Record Services', 'PR Marketing Services', 'Patient & Customer Care(Clinic Assistant)-PCC','Quality Services', 'Admin & Outsource Services', 'Talent Management Services', 'IT Services', 'Purchasing Services','Rehabilition Services(Physiotherapist)', 'Radiology Services', 'Oncology Services', 'Dietetic Services', 'Services Quality Management(SQM) & Customer Services', 'Finance Services', 'Nursing Services'];

function ChangeList() {
var mainList = document.getElementById("main");
var departmentList = document.getElementById("department");
var combine = mainList.options[mainList.selectedIndex].value;
while (departmentList.options.length) {
departmentList.remove(0);
}
var mains = department[combine];
if (mains) {
var i;
for (i = 0; i < mains.length; i++) {
var main = new Option(mains[i], i);

departmentList.options.add(main);
}
}
}

function setValue()
{
document.getElementById("selected_value").value = document.getElementById("department").value;
}
</script>
</select>
</div>
<div class="form-group"> <label for="exampleInputFile"></label>
<input type="file" name="file"/> <p class="help-block">Upload PDF files only.</p> </div>
<button type="submit" name="btn-upload" class="btn btn-default">Submit</button> </form>
</div>
<?php
if(isset($_GET['success']))
{
?>
<label>File Uploaded Successfully... <a href="view.php">click here to view file.</a></label>
<?php
}
else if(isset($_GET['fail']))
{
?>
<label>Problem While File Uploading !</label>
<?php
}
else
{
?>
<label></label>
<?php
}
?>



</div>
<!-- //inner_content_w3_agile_info-->
</div>
<!-- //inner_content-->

然后这是UploadProcess.php

<?php
include_once("../../connection.php");
$link=Connection();
if (!$link)
{
die('Could not connect: ' . mysqli_error($link));
}
mysqli_select_db($link, "doc_db");

//if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
if(isset($_POST['btn-upload']))
{
$fileName = $_FILES['file']['name'];
//$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];
$folder="../../file/";

// new file size in KB
$new_size = $fileSize/1024;
// new file size in KB

// make file name in lower case
$new_file_name = strtolower($fileName);
// make file name in lower case

$final_file=str_replace(' ','-',$new_file_name);

$main = htmlentities(stripslashes(mysqli_real_escape_string($link,$_POST['main'])));
$department = htmlentities(stripslashes(mysqli_real_escape_string($link,$_POST['department'])));

if(move_uploaded_file($tmpName,$folder.$final_file))
{
$sql="INSERT INTO upload(main,department,name,type,size) VALUES('$main','$department','$final_file','$fileType','$new_size')";
mysqli_query($link, $sql);
?>
<script>
alert('successfully uploaded');
window.location.href='Success.php';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='../View/View.php';
</script>
<?php
}
}
?>

最佳答案

在“Upload.php”中:

1) 你错过了<select name="department"... 。所以,写:

<select name="department" id="department" onChange="setValue();" required>

2) 您缺少“selected_value”输入。因此,将其插入到提交按钮之后:

<input type="hidden" id="selected_value" name="selected_value" value="" />

否则,这个文件就可以了。

在“UploadProcess.php”中:

3) 确保创建"file"文件夹。否则,该文件和数据库中的插入工作正常。

不要忘记关闭连接。我建议您实现异常处理。请参阅mysqli sql exception .

编辑1:

我建议您添加 setValue()里面ChangeList() 。所以,替换

<select name="main" id="main" onchange="ChangeList();setValue()" required>

<select name="main" id="main" onchange="ChangeList();" required>

以及ChangeList()功能添加setValue();作为最后一行:

function ChangeList() {
//...
setValue();
}

关于javascript - JS中的下拉列表并想使用PHP保存在数据库中。我不知道,可以帮助我吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44126991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com