Hello,
I have created a php upload form that successfully uploads a pdf document to the server in a specific folder. I am also trying to have the file name updated in a mySQL database table so a dynamic link, linking to the newest file, will work correctly allowing the user to download the new file. When the user browses for a file and uploads the file I am trying to have it update the file name in the database with a table name of "docs" and the field name of "d_file"
I have searched and searched for a solution, and tried editing the code here and there, but I'm obviously not getting it. If anyone has time to look at my code and possibly help in any way it would be MUCH MUCH appreciated.
Thanks in advance!
here is the code:
HTML code for the form-
<form enctype="multipart/form-data" action="add.php" method="POST">
<p align="center">Please choose a file to upload:
<input name="doc" type="file" id="doc">
<br>
<input type="submit" value="Update File">
</p>
</form>
PHP code - (I'm assuming the problem lies in the area that "Writes the information to the database")
<?php
//This is the directory where images will be saved
$target = "../../docs/";
$target = $target . basename( $_FILES['doc']['name']);
//This gets all the other information from the form
$doc=($_FILES['doc']['name']);
// Connects to your Database
$hostname_shockhillDB = "localhost";
$database_shockhillDB = "dbname";
$username_shockhillDB = "usernamer";
$password_shockhillDB = "password";
$shockhillDB = mysql_pconnect($hostname_shockhillDB, $username_shockhillDB, $password_shockhillDB) or trigger_error(mysql_error(),E_USER_ERROR);
//Writes the information to the database
mysql_query("INSERT INTO 'd_file' VALUES ('$doc')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['doc']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>