Jump to content

Insert uploaded file name into MySQL database


froppo

Recommended Posts

Hello,

 

I'm having some frustrations right now. I have built an application form where an applicant inputs their info and then uploads their resume. Even though the resume gets uploaded to a directory on the server i would also like the file name of the resume to get inserted into the mysql database so that I can easily see which resume matches which applicant...if that makes sense. At any rate I'm able to get everything else to work, the applicant's info gets inserted into the database, the resume gets uploaded to the directory, i just can't seem to get the resume file name to also insert into the database.

 

Most of the info i have found on this subject through googleing and the like has been a little over my head and/or a little more complex than what i'm looking for. Here is an extremely simplified version of what I have right now. I have excluded the 'connect to database' code since it's working fine and really doesn't have anything to do with this issue:

<?php 
$target_path = "docs/";
$target_path = $target_path . basename( $_FILES['resume']['name']);
$first_name=$_POST['first_name'];  
$last_name=$_POST['last_name'];  
$middle_init=$_POST['middle_init'];
$resume=$_POST['resume']; 

mysql_query("INSERT INTO `intern` VALUES ('$first_name', '$last_name', '$middle_init',  '$resume')") ;

if (move_uploaded_file($_FILES['resume']['tmp_name'], $target_path));

?>

HTML begins after that.

 

At any rate, any info, help, etc. you could provide would be GREATLY appreciated!

 

Thanks!  :'(

Link to comment
Share on other sites

<?php 
$target_path = "docs/";
$target_path = $target_path . basename( $_FILES['resume']['name']);
$file_name = basename( $_FILES['resume']['name']);
$first_name=$_POST['first_name'];  
$last_name=$_POST['last_name'];  
$middle_init=$_POST['middle_init'];
$resume=$_POST['resume']; 

if (move_uploaded_file($_FILES['resume']['tmp_name'], $target_path)) {
/* presumes values are IN SAME ORDER AS CORRESPONDING FIELDS AND *
/*  that the intended field for the file (resume) follows the middle_int field */
$query = "INSERT INTO intern VALUES ('$first_name', '$last_name', '$middle_init',  '$file_name')";
$result = mysql_query($query) or die();
}else{
/* file was not uploaded */
/* advise user */
exit();
}


?>

Link to comment
Share on other sites

HA! I figured it out!!!

Instead of:

$target_path = $target_path . basename( $_FILES['resume']['name']);

I instead used:

$target_path = $target_path . basename($name = $_FILES['resume']['name']);

I now have the file defined as $name. Now all I have to do is include "$name" in the insert field:

$query = "INSERT INTO `intern` VALUES ('$first_name', '$last_name', '$middle_init', '$name')";


$result = mysql_query($query) or die();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.