emediastudios Posted November 8, 2010 Share Posted November 8, 2010 Hi Everyone, I have a small problem and try to learn from all the help i get here. I have a form that gathers info, emails and inserts info into the database, everything works fine except the file doesnt upload and the file name does not go into the database, instead i get /recruitment in the file field of the databse, instead of recruitment/uploadedfile.pdf Code Below, please help, <?php switch ($_REQUEST['action']) { case 'recruit': foreach($_POST as $key=>$value){ $$key = $value; } if ((!$name) || (!$email) || (!$phone)) { $error_msg = 'Fields marked<span class="gold"> * </span>are required to submit the form'; }elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $error_msg = 'Invalid email address'; } echo "$error_msg","<br><br>"; if ($error_msg == ''){ $add="recruitment/".$_FILES[userfile][name]; $cleaned = stripit($add); $add2 = "../".$cleaned; move_uploaded_file ($_FILES[userfile][tmp_name], $add2); $Q = mysql_query("INSERT INTO recruitment (`name`,`phone`,`email`, `qual`,`exper`,`file`) VALUES ('$name','$phone','$email','$qual','$exper','$cleaned')"); foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $companyname = 'Business college'; $companyemail = '[email protected]'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: ".$name." <".$email.">\r\n"; $headers .= "Reply-To: ".$name." <".$email.">\r\n"; $to = "".$companyname."<".$companyemail.">"; $subject = "Business College Recruitment Form Submission"; $message = '<style type="text/css>"; <!-- .style { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } --> </style> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="style"> <b>Details:</b><br /><br /> <b>Name:</b> '.$name.'<br /> <b>Email:</b> '.$email.'<br /> <b>Mobile No:</b> '.$phone.'<br /> <b>Qualifications:</b><br> '.$qual.'<br /> <b>Experience:</b><br /><br />'.$exper.'<br /><br /> <b>Uploaded resume:</b> http://www.mydomain.com.au/'.$cleaned.' </td> </tr> </table>'; mail($to, $subject, $message, $headers); echo '<table width="99%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="mybody">Hi '.$name.',<p />Thank you for your enquiry. An Consultant will contact you shortly.<br /> <br /> </td> </tr> </table>'; }else{ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } echo ' <form id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=recruit"> <table width="489" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="227">Name:</td> <td width="358"><input type="text" name="name" id="name" value="'.$name.'" /></td> </tr> <tr> <td>Contact Mobile:</td> <td><input type="text" name="phone" id="phone" value="'.$phone.'" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" value="'.$email.'" /></td> </tr> <tr> <td>Relevent Qualifications:</td> <td><textarea name="qual" id="qual" cols="45" rows="5" value="'.$qual.'"></textarea></td> </tr> <tr> <td>Recent Experience:</td> <td><textarea name="exper" id="exper" cols="45" rows="5" value="'.$exper.'"></textarea></td> </tr> <tr> <td>Upload Resume:</td> <td><input type="file" name="userfile" id="userfile" /></td> </tr> <tr> <td><input type="submit" name="submit" id="submit" value="Submit" /></td> <td> </td> </tr> </table> </form>'; } break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218111-upload-pdf-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2010 Share Posted November 8, 2010 Your <form > tag does not have the necessary enctype= attribute so that uploading a file would work. You php code is also not testing if the upload worked successfully before attempting to access any of the uploaded file information. I recommend reading the upload handling section in the php.net documentation - http://us3.php.net/manual/en/features.file-upload.php Quote Link to comment https://forums.phpfreaks.com/topic/218111-upload-pdf-problem/#findComment-1131817 Share on other sites More sharing options...
emediastudios Posted November 8, 2010 Author Share Posted November 8, 2010 Thanks a heap, thats all i needed. Quote Link to comment https://forums.phpfreaks.com/topic/218111-upload-pdf-problem/#findComment-1132008 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.