I want to upload a pdf file but need to make option which pdf is belong. The problem is when i make a severel option then have a second option based on first option. The second option is use js and i dont know how to post it in database.
This is 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-->
Then this is 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
}
}
?>