froppo Posted February 12, 2011 Share Posted February 12, 2011 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! :'( Quote Link to comment Share on other sites More sharing options...
AtomicRax Posted February 12, 2011 Share Posted February 12, 2011 So wait, you just want the file name to be inserted into the database? $resume_file=basename( $_FILES['resume']['name']); the variable $resume_file would then be the name of the file. Quote Link to comment Share on other sites More sharing options...
litebearer Posted February 12, 2011 Share Posted February 12, 2011 <?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(); } ?> Quote Link to comment Share on other sites More sharing options...
froppo Posted February 12, 2011 Author Share Posted February 12, 2011 Hmm...i tried both of those and i still get the same result. File uploads to directory just fine, application info gets inserted into the MySQL database, but uploaded filename is not getting inserted into the database table. :-\ Quote Link to comment Share on other sites More sharing options...
AtomicRax Posted February 12, 2011 Share Posted February 12, 2011 Well if you use a variable like $resume_file=basename( $_FILES['resume']['name']); do a simple echo $resume_file; to see if the filename is printed on the page correctly.. then from there, you'd know you have the filename, it might be a problem somewhere else Quote Link to comment Share on other sites More sharing options...
froppo Posted February 12, 2011 Author Share Posted February 12, 2011 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(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.