Jump to content

[SOLVED] Add image upload and insert record to email script.


emediastudios

Recommended Posts

hi every one.

I am having trouble getting these two scripts to merge into one.

 

They both exist in different files and i have edited them a bit but just cant get it right.

This is my email script, it works fine.

<?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 (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { 
    $error_msg = 'Invalid email address'; 
}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 = 'ryetss@emstr.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);

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;

}


?>

 

and i have edited a old script below to match the above database at stuff but i cant get them to work together.

 

<?php // Store folder for images
	$images_dir = "images/applications";

	// Insert the record making photofilname 0
	mysql_query("INSERT INTO tempmodels (name, email, phone, comments, photofilename, dateadded) VALUES('$name', '$email','$phone','$comments,'$photofilename, '0', NOW())");
$tempmodelid = mysql_insert_id();

	// Counter for multiple fileupload
$counter = 0;

// Limit file types allowed to be updated
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg');

// Convert posted photofilename
$photofilename = $_FILES['photofilename'];

while($counter <= count($_FILES['photofilename']['tmp_name'])) {

if($photofilename['size'][$counter] > 0) {

if(!array_key_exists($photofilename['type'][$counter], $known_photo_types)) {
echo 'File '.($counter+1).' is not a accepted file type!<br />';

}else{	

// Rename the photo to the record id
$filetype = $photofilename['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $tempmodelid.".".$extention;

// Update filename in the database
$sql = mysql_query("UPDATE tempmodels SET photofilename='$filename' WHERE tempmodelid = $tempmodelid");

// Copy the file to the image store folder
move_uploaded_file($photofilename['tmp_name'][$counter], $images_dir."/".$filename);

 }
}
$counter++;
}
?>

 

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.