emediastudios Posted January 5, 2009 Share Posted January 5, 2009 I have a email form and want to add the record to my database. I also want to add a image upload, i have added the field but dont know how to get it working. my email form below. <?php error_reporting(E_ALL); session_start(); require_once 'includes/include.php'; switch ($_REQUEST['action']) { case 'scouting': foreach($_POST as $key=>$value){ $$key = $value; } if ((!$name) || (!$email) || (!$comments) || (!$survey)) { $error_msg = 'Fields marked * are required to submit the form'; }elseif (($_SESSION['security_code'] != $security_code) && (!empty($_SESSION['security_code']))){ $error_msg = 'Please fill in the Verification Image field'; } echo "$error_msg","<br><br>"; if ($error_msg == ''){ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $companyname = 'Jimmys Promotions and Model Agency'; $companyemail = 'rorryss@estuos.com.au'; $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 = "Model Apllication"; $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>Ph No:</b> '.$phone.'<br /><br /> <b>Query:</b><br /><br /> '.$comments.'<br /><br /> <b>Survey:</b><br /> '.$survey.' </td> </tr> </table>'; mail($to, $subject, $message, $headers); $images_dir = "images/applications"; echo '<table width="99%" border="0" cellpadding="0" cellspacing="0"> <tr> <td><br />Hi '.$name.',<p />Thanks for your enquiry. One of our friendly staff will be in touch with you shortly.<p />Regards<p />The team @ '.$companyname.'</td> </tr> </table>'; }else{ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $counter = 1; $number_of_fields = 1; echo '<form id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=scouting" enctype="multipart/form-data"> <table width="550" border="0"> <tr> <td width="199" class="contacttext"><span class="star">*</span><span class="col_box_1"> Your name: </span></td> <td width="341"><input name="name" type="text" class="fields" id="name" value="'.$name.'" /></td> </tr> <tr> <td class="contacttext"><span class="star">*</span><span class="col_box_1"> E-mail address: </span></td> <td><input name="email" type="text" class="fields" id="email" value="'.$email.'" /></td> </tr> <tr> <td class="contacttext_1">Phone: </td> <td><input name="phone" type="text" class="fields" id="phone" value="'.$phone.'" /></td> </tr> <tr> <td class="contacttext"><span class="star">*</span> How did you hear about us? </td> <td><select name="survey" class="fields" id="survey"> <option value="">Please select</option> <option '. ($survey=='Magazine' ? 'selected' : '') .' value="Magazine">Magazine</option> <option '. ($survey=='Internet' ? 'selected' : '') .' value="Internet">Internet</option> <option '. ($survey=='Newspaper' ? 'selected' : '') .' value="Newspaper">Newspaper</option> <option '. ($survey=='Billboard' ? 'selected' : '') .' value="Billboard">Billboard</option> <option '. ($survey=='Yellow pages' ? 'selected' : '') .' value="Yellow pages">Yellow pages</option> <option '. ($survey=='Referal' ? 'selected' : '') .' value="Referal">Referal</option> <option '. ($survey=='Mail out' ? 'selected' : '') .' value="Mail out">Mail out</option> <option '. ($survey=='Drive by' ? 'selected' : '') .' value="Drive by">Drive by</option> <option '. ($survey=='Other' ? 'selected' : '') .' value="Other">Other</option> </select></td> </tr> <tr> <td class="contacttext"><span class="star">* </span>Comments:: </td> <td><textarea name="comments" cols="30" rows="6" class="fields" id="comments">'.$comments.'</textarea></td> </tr> <tr> <td class="contacttext"><span class="star">*</span> Recent snapshot: (max 2meg)</td> <td>'; while($counter <= $number_of_fields){ echo ' <input class="fields2" name="imagename[]" type="file"><br />'; $counter++; } echo '</tr> <tr> <td class="contacttext"><span class="star">*</span> Verification Image: </td> <td><input name="security_code" type="text" class="fields" /></td> </tr> <tr> <td> </td> <td><img src="./captcha.php?width=100&height=40&characters=5" border="1" /></td> </tr> <tr> <td><input name="Submit" type="submit" class="font_5" value="submit" /></td> <td> </td> </tr> </table> </form>'; } break; } ?> My database is as follows Database name = jimmy Fields --------------------------------------- tempmodelid name email phone comments photofilename date. Be so stoked if someone could help me out. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 5, 2009 Share Posted January 5, 2009 add where the email function is. your need to work out the pic upload code sorry. example my contribution. revamped no errors agin lol. <?php $db=mysql_connect("localhost","username","password"); $r=mysql_select_db("database_name",$db)or die(mysql_error()); if(mail($to, $subject, $message, $headers)){ $tempmodelid=mysql_real_escape_string($_POST['tempmodelid']); $name=mysql_real_escape_string($_POST['name']); $email=mysql_real_escape_string($_POST['email']); $phone=mysql_real_escape_string($_POST['phone']); $comments=mysql_real_escape_string($_POST['comments']); $photofilename=mysql_real_escape_string($_POST['photofilename']); $date=date("d/m/y"); $date=mysql_real_esape_string($_PST['date']); $sql="insert into jimmys(tempmodelid,name,email,phone,comments,photofilename,date) values( '$tempmodelid','$name','$email','$phone','$comments','$photofilename','$date')"; $res=mysql_fetch_assoc($sql)or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 5, 2009 Share Posted January 5, 2009 example off the full code no upload added yet. <?php error_reporting(E_ALL); session_start(); $db=mysql_connect("localhost","username","password"); $r=mysql_select_db("database_name",$db)or die(mysql_error()); require_once 'includes/include.php'; switch ($_REQUEST['action']) { case 'scouting': foreach($_POST as $key=>$value){ $$key = $value; } if ((!$name) || (!$email) || (!$comments) || (!$survey)) { $error_msg = 'Fields marked * are required to submit the form'; }elseif (($_SESSION['security_code'] != $security_code) && (!empty($_SESSION['security_code']))){ $error_msg = 'Please fill in the Verification Image field'; } echo "$error_msg","<br><br>"; if ($error_msg == ''){ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $companyname = 'Jimmys Promotions and Model Agency'; $companyemail = 'rorryss@estuos.com.au'; $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 = "Model Apllication"; $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>Ph No:</b> '.$phone.'<br /><br /> <b>Query:</b><br /><br /> '.$comments.'<br /><br /> <b>Survey:</b><br /> '.$survey.' </td> </tr> </table>'; if(mail($to, $subject, $message, $headers)){ $tempmodelid=mysql_real_escape_string($_POST['tempmodelid']); $name=mysql_real_escape_string($_POST['name']); $email=mysql_real_escape_string($_POST['email']); $phone=mysql_real_escape_string($_POST['phone']); $comments=mysql_real_escape_string($_POST['comments']); $photofilename=mysql_real_escape_string($_POST['photofilename']); $date=date("d/m/y"); $date=mysql_real_esape_string($_PST['date']); $sql="insert into jimmys(tempmodelid,name,email,phone,comments,photofilename,date) values( '$tempmodelid','$name','$email','$phone','$comments','$photofilename','$date')"; $res=mysql_fetch_assoc($sql)or die(mysql_error()); $images_dir = "images/applications"; echo '<table width="99%" border="0" cellpadding="0" cellspacing="0"> <tr> <td><br />Hi '.$name.',<p />Thanks for your enquiry. One of our friendly staff will be in touch with you shortly.<p />Regards<p />The team @ '.$companyname.'</td> </tr> </table>'; }else{ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $counter = 1; $number_of_fields = 1; echo '<form id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=scouting" enctype="multipart/form-data"> <table width="550" border="0"> <tr> <td width="199" class="contacttext"><span class="star">*</span><span class="col_box_1"> Your name: </span></td> <td width="341"><input name="name" type="text" class="fields" id="name" value="'.$name.'" /></td> </tr> <tr> <td class="contacttext"><span class="star">*</span><span class="col_box_1"> E-mail address: </span></td> <td><input name="email" type="text" class="fields" id="email" value="'.$email.'" /></td> </tr> <tr> <td class="contacttext_1">Phone: </td> <td><input name="phone" type="text" class="fields" id="phone" value="'.$phone.'" /></td> </tr> <tr> <td class="contacttext"><span class="star">*</span> How did you hear about us? </td> <td><select name="survey" class="fields" id="survey"> <option value="">Please select</option> <option '. ($survey=='Magazine' ? 'selected' : '') .' value="Magazine">Magazine</option> <option '. ($survey=='Internet' ? 'selected' : '') .' value="Internet">Internet</option> <option '. ($survey=='Newspaper' ? 'selected' : '') .' value="Newspaper">Newspaper</option> <option '. ($survey=='Billboard' ? 'selected' : '') .' value="Billboard">Billboard</option> <option '. ($survey=='Yellow pages' ? 'selected' : '') .' value="Yellow pages">Yellow pages</option> <option '. ($survey=='Referal' ? 'selected' : '') .' value="Referal">Referal</option> <option '. ($survey=='Mail out' ? 'selected' : '') .' value="Mail out">Mail out</option> <option '. ($survey=='Drive by' ? 'selected' : '') .' value="Drive by">Drive by</option> <option '. ($survey=='Other' ? 'selected' : '') .' value="Other">Other</option> </select></td> </tr> <tr> <td class="contacttext"><span class="star">* </span>Comments:: </td> <td><textarea name="comments" cols="30" rows="6" class="fields" id="comments">'.$comments.'</textarea></td> </tr> <tr> <td class="contacttext"><span class="star">*</span> Recent snapshot: (max 2meg)</td> <td>'; while($counter <= $number_of_fields){ echo ' <input class="fields2" name="imagename[]" type="file"><br />'; $counter++; } echo '</tr> <tr> <td class="contacttext"><span class="star">*</span> Verification Image: </td> <td><input name="security_code" type="text" class="fields" /></td> </tr> <tr> <td> </td> <td><img src="./captcha.php?width=100&height=40&characters=5" border="1" /></td> </tr> <tr> <td><input name="Submit" type="submit" class="font_5" value="submit" /></td> <td> </td> </tr> </table> </form>'; } break; } } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 5, 2009 Share Posted January 5, 2009 upload code. http://uk.php.net/manual/en/features.file-upload.post-method.php make sure only the extensions needed, are allowed to upload no .exe's this should realy be in the freelance forum aswell. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 5, 2009 Share Posted January 5, 2009 For a basic file uploader, see the manual page Edit: Apologies redarrow; i missed your last post. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 5, 2009 Share Posted January 5, 2009 That was the manual link lol Quote Link to comment Share on other sites More sharing options...
emediastudios Posted January 5, 2009 Author Share Posted January 5, 2009 I used the last code but now the form doesnt show? Thanks for all your help guys Quote Link to comment Share on other sites More sharing options...
emediastudios Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks red arrow for your help, your code looks good, wish i new the little thing stopping it from working. 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.