hi,
I have to store some details about a project in the database and a pfd file about project on the same database.
I have previously written a php script that takes the data and stores in the database and another script to upload the pdf file in a seperate table. However i want to combine these two in a single form and database. Is that possible??? Please help
Thank you;
the two scripts are as follows
[php]<?php
require(‘connect.php’);
include(“auth.php”); //include auth.php file on all secure pages
$status = “”;
if(isset($_POST[‘new’]) && $_POST[‘new’]==1)
{
$trn_date = date(“Y-m-d H:i:s”);
$Title =$_REQUEST[‘Title’];
$Authors =$_REQUEST[‘Authors’];
$Document_No =$_REQUEST[‘Document_No’];
$Proj_No = $_REQUEST[‘Proj_No’];
$Date_of_issue =$_REQUEST[‘Date_of_issue’];
$class =$_REQUEST[‘class’];
$Sponsors =$_REQUEST[‘Sponsors’];
$Remarks =$_REQUEST[‘Remarks’];
$Key_words =$_REQUEST[‘Key_words’];
$Abstract =$_REQUEST[‘Abstract’];
$No_of_copies =$_REQUEST[‘No_of_copies’];
$Misc =$_REQUEST[‘Misc’];
$submittedby = $_SESSION[“username”];
$ins_query=“insert into new_record1(trn_date
,Title
,Authors
,Document_No
,Proj_No
,Date_of_issue
,class
,Sponsors
,Remarks
,Key_words
,Abstract
,No_of_copies
,Misc
,submittedby
)values(’$trn_date’,’$Title’,’$Authors’,’$Document_No’,’$Proj_No’,’$Date_of_issue’,’$class’,’$Sponsors’,’$Remarks’,’$Key_words’,’$Abstract’,’$No_of_copies’,’$Misc’,’$submittedby’)”;
mysql_query($ins_query) or die(mysql_error());
$status = “New Record Inserted Successfully.View Inserted Record”;
}
?>
Dashboard | View Records | Logout
Insert New Record
Restricted UnRestricted In-House ADA ISRO DRDO BOSCH Others<?php echo $status; ?>
[php]
<?php include("auth.php"); // Check if a file has been uploaded if(isset($_FILES['uploaded_file'])) { // Make sure the file was sent without errors if($_FILES['uploaded_file']['error'] == 0) { // Connect to the database $dbLink = new mysqli('localhost', 'root', 'root', 'F_proj'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name'])); $size = intval($_FILES['uploaded_file']['size']); $submittedby = $_SESSION["username"]; // Create the SQL query $query = " INSERT INTO `file` ( `name`, `mime`, `size`, `data`, `created`,`submittedby` ) VALUES ( '{$name}', '{$mime}', {$size}, '{$data}', NOW(),'$submittedby' )"; // Execute the query $result = $dbLink->query($query); // Check if it was successfull if($result) { Echo "Your file was uploaded successfully"; } else { echo 'Error! Failed to insert the file' . "{$dbLink->error}"; } } else { echo 'An error accured while the file was being uploaded. ' . 'Error code: '. intval($_FILES['uploaded_file']['error']); } // Close the mysql connection $dbLink->close(); } else { echo 'Error! A file was not sent!'; } // Echo a link back to the main page echo '
Click here to go back
'; ?> MySQL file upload example<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Dashboard | View Records | Logout