Jump to content

[SOLVED] PHP form submitted to database works fine...I need it send email.


sandbudd

Recommended Posts

I have a form that submits to the database great but I also need it send the information to an email when submitted.  Any help would be great!  I don't know if you need the entire code but here is all of it.

 

<html> 
<head> 
<title>Manage Contact Log</title> 
</head> 
<body> 
<?php 
/************************************************************************* 
               control code for application 
*************************************************************************/ 

//submit button was pressed so call the process form function 
if (isset($_POST['submit'])) 
{ 
  process_form(); 
  die(); 
}//end if 


//call the get_data function 
if (isset($_GET['id'])) 
{ 
  get_data(); 
}//endif 


//nothing chosen so list the dma's 
if ((empty($_POST))&&(empty($_GET))) 
{ 
  list_users(); 
  die(); 
}//end if 


//request to add a new contact so call the show_form function 
if ((isset($_GET['action']))&&($_GET['action']=='add')) 
{ 
  show_form(); 
}//endif 



/************************************************************************* 
               get the data for an individual contact 
*************************************************************************/ 

function get_data() 
{ 
    //validate the id has been passed at that it is a number 
    if ((empty($_GET['id']))||(is_nan($_GET['id']))) 
    { 
        //there was a problem so list the users again 
      list_users(); 
      //kill the script 
      die(); 
    }else{ 
      //all is ok and assign the data to a local variable 
      $id = $_GET['id']; 
    }//end if 
$sql = "select * from rfq where id = {$id} order by id;"; 
    $result = conn($sql); 
    if (mysql_num_rows($result)==1){ 
      //call the form and pass it the handle to the resultset 
      show_form($result); 
    }else{ 
      $msg = "No data found for FWA Form"; 
      confirm($msg); 
      //call the list users function 
      list_users(); 
    }//end if  
}//end function 


/************************************************************************* 
               show the input / edit form 
*************************************************************************/ 
function show_form($handle='',$data='') 
{ 
  //$handle is the link to the resultset, the ='' means that the handle can be empty / null so if nothing is picked it won't blow up 
  
  //set default values 
  $id  = ''; 
  $name  = ''; 
  $company  = ''; 
  $address  = ''; 
  $city  = ''; 
  $zip      = ''; 
  $email  = ''; 
  $phone  = ''; 
  $fax  = ''; 
  $state  = ''; 
  $typeii  = ''; 
  $type3      = ''; 
  $burnish  = ''; 
  $chromate  = ''; 
  $hex  = ''; 
  $impregnation  = ''; 
  $strip      = ''; 
  $partnumber  = ''; 
  $partdescription  = ''; 
  $alloy  = ''; 
  $quantity  = ''; 
  $specifications      = ''; 
  $color  = ''; 
  $reoccur  = ''; 
  $internet  = ''; 
  $internetdirectory  = ''; 
  $referral      = ''; 
  $yellowpages  = ''; 
  $tradeshow  = ''; 
  $other  = ''; 
  $notes  = ''; 
  $value      = 'Add';  //submit button value 
  $action     = 'add';  //default form action is to add a new dma/station to db 

  //set the action based on what the user wants to do 
  if ($handle) 
  { 
    //set form values for button and action 
    $action = "edit"; 
    $value  = "Update"; 
    
    //get the values from the db resultset 
    $row = mysql_fetch_array($handle); 
    $id  = $row['id']; 
    $name  = $row['name']; 
    $company  = $row['company']; 
    $address  = $row['address']; 
    $city  = $row['city']; 
    $zip          = $row['zip']; 
    $email  = $row['email']; 
    $phone  = $row['phone']; 
    $fax  = $row['fax'];
    $state  = $row['state']; 
    $typeii  = $row['typeii']; 
    $type3  = $row['type3']; 
    $burnish = $row['burnish']; 
    $chromate  = $row['chromate']; 
    $hex  = $row['hex']; 
    $impregnation  = $row['impregnation']; 
    $strip  = $row['strip']; 
    $partnumber  = $row['partnumber']; 
    $partdescription   = $row['partdescription']; 
    $alloy  = $row['alloy']; 
    $quantity  = $row['quantity']; 
    $specifications  = $row['specifications']; 
    $color  = $row['color']; 
    $reoccur  = $row['reoccur']; 
    $internet          = $row['internet']; 
    $internetdirectory  = $row['internetdirectory']; 
    $referral  = $row['referral']; 
    $yellowpages  = $row['yellowpages']; 
    $tradeshow  = $row['tradeshow']; 
    $other  = $row['other']; 
    $notes          = $row['notes']; 
  }//end if 
  
  //error handling from the processing form function 
  if($data != '') 
  { 
    $elements = explode("|",$data); 
        $id     = $elements[0]; 
        $name     = $elements[1]; 
        $company     = $elements[2]; 
        $address     = $elements[3]; 
        $city     = $elements[4]; 
        $zip             = $elements[5]; 
        $email     = $elements[6]; 
        $phone     = $elements[7]; 
        $fax     = $elements[8]; 
        $state     = $elements[9]; 
        $typeii     = $elements[10]; 
        $type3     = $elements[11]; 
        $burnish             = $elements[12]; 
        $chromate     = $elements[13]; 
        $hex     = $elements[14]; 
        $impregnation     = $elements[15]; 
        $strip     = $elements[16]; 
        $partnumber     = $elements[17]; 
        $partdescription             = $elements[18]; 
        $alloy     = $elements[19]; 
        $quantity     = $elements[20]; 
        $specifications     = $elements[21]; 
        $color     = $elements[22]; 
        $reoccur     = $elements[23]; 
        $internet             = $elements[24]; 
        $internetdirectory     = $elements[25]; 
        $referral     = $elements[26]; 
        $yellowpages     = $elements[27]; 
        $tradeshow     = $elements[28]; 
        $other     = $elements[29]; 
        $notes             = $elements[30]; 
  } 
?> 

<body> 

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php  echo $action?>"> 
  <table align="left">
    
    <tr valign="baseline">
      <td width="116" align="right" nowrap><input type="hidden" value="<?php echo $id?>" name="id"><div align="left">Name:</div></td>
      <td width="193"><input type="text" name="name" value="<?php echo $name ?>" size="32"></td>
      <td width="113"> </td>
      <td width="68" align="right" nowrap><div align="left">Company:</div></td>
      <td width="205"><input type="text" name="company" value="<?php echo $company ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Address:</div></td>
      <td><input type="text" name="address" value="<?php echo $address ?>" size="32"></td>
      <td> </td>
      <td align="right" nowrap><div align="left">City:</div></td>
      <td><input type="text" name="city" value="<?php echo $city ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left"></div></td>
      <td> </td>
      <td> </td>
      <td align="right" nowrap><div align="left">Zip:</div></td>
      <td><input type="text" name="zip" value="<?php echo $zip ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Email:</div></td>
      <td><input type="text" name="email" value="<?php echo $email ?>" size="32"></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Phone:</div></td>
      <td><input type="text" name="phone" value="<?php echo $phone ?>" size="32"></td>
      <td> </td>
      <td align="right" nowrap>Fax:</td>
      <td><input type="text" name="fax" value="<?php echo $fax ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap> </td>
      <td><select name="state" value="<?php echo $state ?>">
        <option value="alabama">Alabama</option>
        <option value="Alaska">Alaska</option>
        <option value="Arizona">Arizona</option>
        <option value="Arkansas">Arkansas</option>
        <option value="California">California</option>
        <option value="Colorado">Colorado</option>
        <option value="Connecticut">Connecticut</option>
        <option value="Delaware">Delaware</option>
        <option value="Florida">Florida</option>
        <option value="Georgia">Georgia</option>
        <option value="Hawaii">Hawaii</option>
        <option value="idaho">idaho</option>
        <option value="Illinois">Illinois</option>
        <option value="Indiana">Indiana</option>
        <option value="Iowa">Iowa</option>
        <option value="Kansas">Kansas</option>
        <option value="Kentucky">Kentucky</option>
        <option value="Louisiana">Louisiana</option>
        <option value="Maine">Maine</option>
        <option value="Maryland">Maryland</option>
        <option value="Massachusetts">Massachusetts</option>
        <option value="Michigan">Michigan</option>
        <option value="Minnesota">Minnesota</option>
        <option value="Mississippi">Mississippi</option>
        <option value="Missouri">Missouri</option>
        <option value="Montana">Montana</option>
        <option value="Nebraska">Nebraska</option>
        <option value="Nevada">Nevada</option>
        <option value="New Hampshire">New Hampshire</option>
        <option value="New Jersey">New Jersey</option>
        <option value="New Mexico">New Mexico</option>
        <option value="New York">New York</option>
        <option value="North Carolina">North Carolina</option>
        <option value="North Dakota">North Dakota</option>
        <option value="Ohio">Ohio</option>
        <option value="Oklahoma">Oklahoma</option>
        <option value="Oregon">Oregon</option>
        <option value="Pennsylvania">Pennsylvania</option>
        <option value="Rhode Island">Rhode Island</option>
        <option value="South Carolina">South Carolina</option>
        <option value="South Dakota">South Dakota</option>
        <option value="Tennessee">Tennessee</option>
        <option value="Texas">Texas</option>
        <option value="Utah">Utah</option>
        <option value="Vermont">Vermont</option>
        <option value="Virginia">Virginia</option>
        <option value="Washington">Washington</option>
        <option value="West Virginia">West Virginia</option>
        <option value="Wisconsin">Wisconsin</option>
        <option value="Wyoming">Wyoming</option>
      </select></td>
      <td> </td>
      <td align="right" nowrap> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left" class="style1">
        <div align="left">Process requested (please check all that apply):</div>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
<?php 

if ($typeii != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$typeii = "NO";
}
else {
$typeii = "YES";
}

if ($type3 != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$type3 = "NO";
}
else {
$type3 = "YES";
}

if ($burnish != NULL) {  // if not empty meaning it's selected it will be YES if not it will be NO
$burnish = "NO";
}
else {
$burnish = "YES";
}

if ($chromate != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$chromate = "NO";
}
else {
$chromate = "YES";
}

if ($hex != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$hex = "NO";
}
else {
$hex = "YES";
}

if ($impregnation != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$impregnation = "NO";
}
else {
$impregnation = "YES";
}

if ($strip != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$strip = "NO";
}
else {
$strip = "YES";
}

if ($reoccur != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$reoccur = "NO";
}
else {
$reoccur = "YES";
}

if ($internet != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$internet = "NO";
}
else {
$internet = "YES";
}

if ($yellowpages != NULL) { // if not empty meaning it's selected it will be YES if not it will be NO
$yellowpages = "NO";
}
else {
$yellowpages = "YES";
}

?>


        <div align="left">
          <input type="checkbox" name="typeii" value="<?php echo $typeii ?>" id="checkbox">
      Type II (Conventional Anodize)</div></td>
      <td> </td>
      <td colspan="2" align="right" nowrap><div align="left">
        <input type="checkbox" name="type3" value="<?php echo $type3 ?>" id="checkbox3">
      Type III (Hard Coat Anodize)</div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input type="checkbox" name="burnish" value="<?php echo $burnish ?>" id="checkbox4">
      (Burnish, Deburr)</div></td>
      <td> </td>
      <td colspan="2" align="right" nowrap><div align="left">
        <input type="checkbox" name="chromate" value="<?php echo $chromate ?>" id="checkbox5">
      Chromate Conversion</div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input type="checkbox" name="hex" value="<?php echo $hex ?>" id="checkbox7">
      Chromate Conversion Hex-free</div></td>
      <td> </td>
      <td colspan="2" align="right" nowrap><div align="left">
        <input type="checkbox" name="impregnation" value="<?php echo $impregnation ?>" id="checkbox6">
      Impregnation</div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap>
        
        <div align="left">
          <input type="checkbox" name="strip" value="<?php echo $strip ?>" id="checkbox8">
      Strip</div></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap> </td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Part Number</div></td>
      <td colspan="4"><input type="text" name="partnumber" value="<?php echo $partnumber ?>" size="100"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Part Description</div></td>
      <td colspan="4"><input type="text" name="partdescription" value="<?php echo $partdescription ?>" size="100"></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap><div align="left">Alloy:</div></td>
      <td><input type="text" name="alloy" value="<?php echo $alloy ?>" size="32"></td>
      <td> </td>
      <td>Quantity</td>
      <td><input type="text" name="quantity" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Specifications</div></td>
      <td><input type="text" name="specifications" value="<?php echo $specifications ?>" size="32"></td>
      <td> </td>
      <td>Color</td>
      <td><input type="text" name="color" value="<?php echo $color ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left" class="style1">
        <div align="left">How did you hear about us?</div>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left">
        <table width="100%" border="0" cellspacing="3" cellpadding="0">
          <tr>
            <td><input type="checkbox" name="reoccur" value="<?php echo $reoccur ?>" id="checkbox22">
              I am a repeat customer</td>
            <td><input type="checkbox" name="internet" value="<?php echo $internet ?>" id="checkbox9"></td>
            <td>Internet:</td>
            <td>Internet Directory:</td>
            <td><input type="text" name="internetdirectory" value="<?php echo $internetdirectory ?>" size="32"></td>
          </tr>
          <tr>
            <td>Referral:
              <input type="text" name="referral" value="" size="32"></td>
            <td><input type="checkbox" name="yellowpages" value="<?php echo $yellowpages ?>" id="checkbox10"></td>
            <td>Yellow Pages:</td>
            <td>Tradeshow:</td>
            <td><input type="text" name="tradeshow" value="<?php echo $tradeshow ?>" size="32"></td>
          </tr>
          <tr>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
        </table>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" nowrap><div align="left">Other:
          <textarea name="other" value="<?php echo $other ?>" cols="80"></textarea>
      </div></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left"></div></td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr valign="baseline">
      <td colspan="5" align="right" valign="middle" nowrap><div align="left"></div>        
        <div align="left">Notes/ Special Request
          <textarea name="notes" value="<?php echo $notes ?>" cols="80"></textarea>
      </div></td>
    </tr>
    
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td><input name="submit" type="submit" value="<?php echo $value ?>"> <input name="reset" type="reset" value="Clear Form"></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
  </table>
  <div align="left">
  </div>
</form>


<? 
}//end function 


/************************************************************************* 
               list all the DMA/Stations in the db 
*************************************************************************/ 
function list_users() 
{ 
    $y = 0; //counter 
    $sql = "select * from rfq order by id;";  
    $result = conn($sql); 

// include "smsinclude.php"; 


  echo "<table width=\"700\" cellpadding=\"0\" cellspacing=\"0\"> 
        	<tr><td style=\"font-size:18px; font-weight:bold;\">Manage Request for Quote</td></tr> 
        	<tr>
			<td valign=\"top\"><br><a href='".$_SERVER['PHP_SELF']."?action=add'>Add an additional Request</a><br></td>
		</tr>
	</table><br>
	<table width=\"800\" cellpadding=\"5\" cellspacing=\"0\">";
  
         
     if (mysql_num_rows($result)){ 
      //show a list of kids with name as a link to the prepopulated form with their data in it 
      while($rows = mysql_fetch_array($result)){ 
        
        //change row background color 
        (($y % 2) == 0) ? $bgcolor = "#F8F7F2" : $bgcolor=" #FFFFFF"; 
        
        //build strings to make life easier 

    $id  = $rows['id']; 
    $name  = $rows['name']; 
    $company  = $rows['company']; 
    $address  = $rows['address']; 
    $city  = $rows['city']; 
    $zip          = $rows['zip']; 
    $email  = $rows['email']; 
    $phone  = $rows['phone']; 
    $fax  = $rows['fax']; 
    $state  = $rows['state']; 
    $typeii  = $rows['typeii']; 
    $type3  = $rows['type3']; 
    $burnish = $rows['burnish']; 
    $chromate  = $rows['chromate']; 
    $hex  = $rows['hex']; 
    $impregnation  = $rows['impregnation']; 
    $strip  = $rows['strip']; 
    $partnumber  = $rows['partnumber']; 
    $partdescription   = $rows['partdescription']; 
    $alloy  = $rows['alloy']; 
    $quantity  = $rows['quantity']; 
    $specifications  = $rows['specifications']; 
    $color  = $rows['color']; 
    $reoccur  = $rows['reoccur']; 
    $internet          = $rows['internet']; 
    $internetdirectory  = $rows['internetdirectory']; 
    $referral  = $rows['referral']; 
    $yellowpages  = $rows['yellowpages']; 
    $tradeshow  = $rows['tradeshow']; 
    $other  = $rows['other']; 
    $notes          = $rows['notes']; 


        
        //pass the url to delete the correct table  NOT SURE if its RFQ or fwaform or....
  		$field_data = "rfq";	

        //convert status to readable string from 1 or 0  might need this for the checkboxes
        ($status == 0) ? $status = "Available to contact" : $status = "Do not contact at present."; 
        
        //echo out the row 
        echo "<tr style='background-color:$bgcolor;'>
			<td>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\" height=\"30\" valign=\"middle\"><b>Request For Quote #: $id</b></a></td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
						<td valign=\"top\" width=\"230\"><b>Name:</b> $name</td>
						<td valign=\"top\" width=\"250\"><b>Company:</b> $company</td>
						<td valign=\"top\" width=\"320\"><b>Address:</b> $address</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"230\"><b>City:</b> $city</td>
						<td valign=\"top\" width=\"250\"><b>State:</b> $state</td>
						<td valign=\"top\" width=\"320\"><b>Zip:</b> $zip</td>


					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"230\"><b>Email:</b> $email</td>
						<td valign=\"top\" width=\"250\"><b>Phone:</b> $phone</td>
						<td valign=\"top\" width=\"320\"><b>Fax:</b> $fax</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
						<td valign=\"top\" width=\"800\"><b>TypeII:</b> $typeii     <b>Type3:</b> $type3      <b>Burnish:</b> $burnish     <b>Chromate:</b> $chromate     <b>Hex:</b> $hex     <b>Impregnation:</b> $impregnation      <b>Strip:</b> $strip</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"250\"><b>Part Number:</b> $partnumber</td>
						<td valign=\"top\" width=\"380\"><b>Part Description:</b> $partdescription</td>
						<td valign=\"top\" width=\"170\"><b>Alloy:</b> $alloy</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\"><b>Specifications:</b> $specifications</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"230\"><b>Quantity:</b> $quantity</td>
						<td valign=\"top\" width=\"570\"><b>Color:</b> $color</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
						<td valign=\"top\" width=\"800\"><b>Repeat:</b> $reoccur     <b>Internet:</b> $internet     <b>Internet Directory:</b> $internetdirectory     <b>Referral:</b> $referral     <b>Yellowpages:</b> $yellowpages     <b>Tradeshow:</b> $tradeshow</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\"><b>Other:</b> $other</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td valign=\"top\" width=\"800\"><b>Notes:</b> $notes</td>
					</tr>
				</table>
				<table width=800 cellpadding=5 cellspacing=5 border=0>
					<tr>
						<td width=\"800\" valign=\"top\" height=\"30\" valign=\"middle\"><a href='delete_record.php?id=$id&field_data=$field_data'><b>Delete Request for Quote #$id</b></a></td>
					</tr>
				</table>
			</td></tr>";
   
    $y++;  //increment the counter 
      }//end while 
      echo "</table><br>"; 

  }else{ 
    //handle no results 
    echo "<tr><td colspan='20' align='center'><b>No data found.</b></td></tr>"; 
  }//endif 
} 


/************************************************************************* 
               add / update the contact's data 
*************************************************************************/ 
function process_form() 
{ 
  $id  = ''; 
  $name  = ''; 
  $company  = ''; 
  $address  = ''; 
  $city  = ''; 
  $zip  = ''; 
  $email  = ''; 
  $phone  = ''; 
  $fax  = ''; 
  $state  = ''; 
  $typeii     = ''; 
  $type3  = ''; 
  $burnish  = ''; 
  $chromate  = ''; 
  $hex  = ''; 
  $impregnation     = ''; 
  $strip  = ''; 
  $partnumber  = ''; 
  $partdescription  = ''; 
  $alloy  = ''; 
  $quantity     = ''; 
  $specifications  = ''; 
  $color  = ''; 
  $reoccur  = ''; 
  $internet  = ''; 
  $internetdirectory     = ''; 
  $referral  = ''; 
  $yellowpages  = ''; 
  $tradeshow  = ''; 
  $other  = ''; 
  $notes  = ''; 
  $action = ''; 
  $status = 0;    //default value 

  $id  = @$_POST['id']; 
  $name  = @$_POST['name'];  
  $company  = @$_POST['company']; 
  $address  = @$_POST['address'];  
  $city  = @$_POST['city']; 
  $zip     = @$_POST['zip'];          
  $email  = @$_POST['email']; 
  $phone  = @$_POST['phone'];  
  $fax  = @$_POST['fax']; 
  $state  = @$_POST['state']; 
  $typeii  = @$_POST['typeii'];  
  $type3  = @$_POST['type3']; 
  $burnish     = @$_POST['burnish'];          
  $chromate  = @$_POST['chromate']; 
  $hex  = @$_POST['hex'];  
  $impregnation  = @$_POST['impregnation']; 
  $strip  = @$_POST['strip'];  
  $partnumber  = @$_POST['partnumber']; 
  $partdescription     = @$_POST['partdescription'];          
  $alloy  = @$_POST['alloy']; 
  $quantity  = @$_POST['quantity'];  
  $specifications  = @$_POST['specifications']; 
  $color  = @$_POST['color'];  
  $reoccur  = @$_POST['reoccur']; 
  $internet     = @$_POST['internet'];          
  $internetdirectory  = @$_POST['internetdirectory']; 
  $referral  = @$_POST['referral'];  
  $yellowpages  = @$_POST['yellowpages']; 
  $tradeshow  = @$_POST['tradeshow'];  
  $other  = @$_POST['other']; 
  $notes     = @$_POST['notes'];          
  $action = @$_GET['action']; 
  $status = @$_POST['status']; 
  
  //if no status is set, defaults to 0 (allow contact) 
  if ($status == ''){$status = 0; } 
    
  if (($name=='')||($company=='')||($address=='')||($city=='')||($zip=='')) 
  { 
    $msg = "Some data from the form was forgotten. Please fill in the entire form."; 
    confirm($msg); 
    $data = "$id|$name|$company|$address|$city|$zip|$email|$phone|$fax|$state|$typeii|$type3|$burnish|$chromate|$hex|$impregnation|$strip|$partnumber|$partdescription|$alloy|$quantity|$specifications|$color|$reoccur|$internet|$internetdirectory|$referral|$yellowpages|$tradeshow|$other|$notes"; 
    show_form('',$data); 
    die(); 
  }//end if 
  
  //You could add some validation of the data ( I recommend it and its a great way to get your feet wet with php ) 

  if ($action == "add") 
  { 
    $sql = "insert into rfq (name, company, address, city, zip, email, phone, fax, state, typeii, type3, burnish, chromate, hex, impregnation, strip, partnumber, partdescription, alloy, quantity, specifications, color, reoccur, internet, internetdirectory, referral, yellowpages, tradeshow, other, notes) values('{$name}','{$company}','{$address}','{$city}','{$zip}','{$email}','{$phone}','{$fax}','{$state}','{$typeii}','{$type3}','{$burnish}','{$chromate}','{$hex}','{$impregnation}','{$strip}','{$partnumber}','{$partdescription}','{$alloy}','{$quantity}','{$specifications}','{$color}','{$reoccur}','{$internet}','{$internetdirectory}','{$referral}','{$yellowpages}','{$tradeshow}','{$other}','{$notes}');"; 
    $msg = "Record successfully added"; 
  }elseif($action=="edit"){ 
    $sql = "update rfq set name = '{$name}', company = '{$company}', address = '{$address}', city = '{$city}', zip = '{$zip}', email = '{$email}', phone = '{$phone}', fax = '{$fax}', state = '{$state}', typeii = '{$typeii}', type3 = '{$type3}', burnish = '{$burnish}', chromate = '{$chromate}', hex = '{$hex}', impregnation = '{$impregnation}', strip = '{$strip}', partnumber = '{$partnumber}', partdescription = '{$partdescription}', alloy = '{$alloy}', quantity = '{$quantity}', specifications = '{$specifications}', color = '{$color}', reoccur = '{$reoccur}', internet = '{$internet}', internetdirectory = '{$internetdirectory}', referral = '{$referral}', yellowpages = '{$yellowpages}', tradeshow = '{$tradeshow}', other = '{$other}', notes = '{$notes}' where id = {$id};"; 
    $msg = "Record successfully updated"; 
  } 
  $result = conn($sql); 
  if (mysql_errno()==0) 
  { 
    confirm($msg); 
    list_users(); 
  }else{ 
    $msg = "There was a problem adding the user to the database. Error is:".mysql_error(); 
    confirm($mag); 
  }//end if 
      
} 



/************************************************************************* 
               db connection function 
*************************************************************************/ 
function conn($sql) 
{    

$host = "****"; 
$user = "*****"; 
$pass = "****"; 
$db     = "*****"; 


    //echo "commnecing connection to local db<br>"; 
    
    if (!($conn=mysql_connect($host, $user, $pass)))  { 
        printf("error connecting to DB by user = $user and pwd=$pass"); 
        exit; 
    } 
    $db3=mysql_select_db($db,$conn) or die("Unable to connect to local database"); 

    $result = mysql_query($sql) or die ("Can't run query because ". mysql_error()); 
    
    return $result; 
    
}//end function      

/************************************************************************* 
               alert box popup confimation message function 
*************************************************************************/ 
function confirm($msg) 
{ 
  echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>"; 
}//end function 

?>

Once you have successfully added the data, then use php mail function to send out the e-mail

 

put it in here.

  $result = conn($sql); 
  if (mysql_errno()==0) 
  { 
// Who you sending mail to
$to = "[email protected]";
// Subject
$subject = "Here is the subject";
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail($to, $subject, $message);

    confirm($msg); 
    list_users(); 
  }else{

 

Ray

I have this code for uploading multiple files or pictures. Can change the code to fit your needs. it will resample images to a specific size and create a thumbnail if need be. i fyou need help customizing it let me know.

<?php
$user = "ray";
$image_path = "C:/Inetpub/wwwroot/phpforum/$user/images/";          //Absolute path to where files are uploaded
$thumb_path = "C:/Inetpub/wwwroot/phpforum/$user/images/thumbs/";   //Absolute path to where thumbs are to be stored if you want this
$file_path = "C:/Inetpub/wwwroot/phpforum/$user/";                  // Absolute path to the files folder
$size_limit = "yes";                                                //do you want a size limit yes or no.
$limit_size = "2097152";                                            //How big do you want size limit to be in bytes
$limit_ext = "yes";                                                 //do you want to limit the extensions of files uploaded
$ext_count = "8";                                                   //total number of extensions in array below
$extensions = array(".jpg", ".jpeg", ".png", ".gif", ".doc", ".pdf", ".txt", ".xls");   //List extensions you want files uploaded to be
$im_array = array("image/x-png", "image/pjpeg", "image/gif", "image/jpeg");             //List of image types make sure image type extension is in above array
$files = 6;   // Change this line for the number of upload you want to allow

function resampleimage($maxsize, $sourcefile, $destination, $filetype, $quality){
  // CHECK TO SEE IF THE IMAGE EXISTS FIRST
  if(file_exists($sourcefile)){
  // FIRST WE GET THE CURRENT IMAGE SIZE
  $g_is=getimagesize($sourcefile);
    /********* CALCULATE THE WIDTH AND THE HEIGHT ***************/
    // CHECK TO SEE IF THE WIDTH AND HEIGHT ARE ALREADY SMALLER THAN THE MAX SIZE
    if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){
    // LEAVE WIDTH AND HEIGHT ALONE IF IMAGE IS SMALLER THAN MAXSIZE
    $new_width=$g_is[0];
    $new_height=$g_is[1];
    } else {
    // GET VALUE TO CALCULATE WIDTH AND HEIGHT
    $w_adjust = ($maxsize / $g_is[0]);
    $h_adjust = ($maxsize / $g_is[1]);
      // CHECK TO WHICH DIMENSION REQUIRES THE SMALLER ADJUSTMENT
      if($w_adjust <= $h_adjust){
      // CALCULATE WIDTH AND HEIGHT IF THE WIDTH VALUE IS SMALLER
      $new_width=($g_is[0]*$w_adjust);
      $new_height=($g_is[1]*$w_adjust);
      } else {
      // CALCULATE WIDTH AND HEIGHT IF THE HEIGHT VALUE IS SMALLER
      $new_width=($g_is[0]*$h_adjust);
      $new_height=($g_is[1]*$h_adjust);
      }
    }
//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
switch($filetype) {
	case 'image/pjpeg':
		$img_src = imagecreatefromjpeg($sourcefile);
		break;
	case 'image/jpeg':
		$img_src = imagecreatefromjpeg($sourcefile);
		break;
	case 'image/x-png':
		$img_src = imagecreatefrompng($sourcefile);
		break;
	case 'image/gif':
		$img_src = imagecreatefromgif($sourcefile);
		break;
	default:
		echo("Error Invalid Image Type");
		die;
		break;
}
  // CREATE THE TRUE COLOR IMAGE WITH NE WIDTH AND HEIGHT
  $img_dst=imagecreatetruecolor($new_width,$new_height);
  // RESAMPLE THE IMAGE TO NEW WIDTH AND HEIGHT
  imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]);
  // OUTPUT THE IMAGE AS A JPEG.
  // THIS CAN BE CHANGED IF YOU WANT TRANSPARENCY OR PREFER ANOTHER FORMAT. MAKE SURE YOU CHANGE HEADER ABOVE.
  imagejpeg($img_dst, $destination, $quality);
  // DESTROY THE NEW IMAGE
  imagedestroy($img_dst);
  return true;
  } else {
  return false;
  }
}

if(!isset($_POST['submit'])){
$extens = '';

        if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) {
           $extens = "any extension";
        } else {
        $ext_count2 = $ext_count+1;
        for($counter=0; $counter<$ext_count; $counter++) {
            $extens .= "  $extensions[$counter]";
        }
        }
        if (($limit_size == "") or ($size_limit != "yes")) {
            $limit_size = "any size";
        } else {
            $limit_size .= " bytes";
            $mb_size = ($limit_size/1048576);
        }
        $pichead = "<li><font size=\"2\" color=660000>File extension must be $extens<b>";
        $pichead .="</b></font>
        <li><font size=\"2\" color=660000>Maximum file size is $limit_size ($mb_size MB)</font></li>
        <li><font size=\"2\" color=660000>No spaces in the filename</font></li>";
?>
<html>
<head>
<title>HTML Form for uploading image to server</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<html>
<title>Upload Files</title>
<body>
<p><? echo $pichead; ?></p>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Files:<br />
<?php
for($i=1; $i<=$files; $i++){
echo "File $i <input type=\"file\" name=\"files[]\" /><br />\n";
}
?>
<input type="submit" name=submit value="Send" />
</p>
</form>
<?php
} else {
$i=0;
$quality = "75";
  foreach ($_FILES["files"]["error"] as $key => $error) {
  $file_name =  $_FILES["files"]['name'][$i]; // can call this anything you like this will take the original name
  $file =  $_FILES["files"]['tmp_name'][$i];
  $file_size = $_FILES["files"]['size'][$i];
  $file_type = $_FILES["files"]['type'][$i];
  $endresult = "<font size=\"4\" color=990000>$file_name uploaded successfully</font>";
    if ($file_name == "") {
    $pic = $i+1;
    $endresult = "<font size=\"4\" color=990000>Pic#$pic Not selected</font>";
    }else{
      if(file_exists("$file_path/$file_name") || file_exists("$image_path/$file_name") || file_exists("$thumb_path/$file_name")) {
      $endresult = "<font size=\"4\" color=990000>File Already Existed in your home directory</font>";
      } else {
        if (($size_limit == "yes") && ($limit_size < $file_size)) {
        $endresult = "<font size=\"4\" color=990000>File was to big</font>";
        } else {
        $ext = strrchr($file_name,'.');
          if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
          $endresult = "<font size=\"4\" color=990000>File is wrong type</font>";
          }else{
            // Check what type of file it is
            if(!in_array($file_type, $im_array)){
            //echo $file_type;
            // Move none image files
            move_uploaded_file($file, $file_path.$file_name);
            } else {
            //echo $file_type;
            // Save full size image with max width/height
            resampleimage("1280", $file, $image_path.$file_name, $file_type, $quality);  // Comment this line out if you don't want to resize the image change the "800" to the size you want
            // Save thumb image with max width/height of 200
            resampleimage("200", $file, $thumb_path.$file_name, $file_type, $quality); // Comment this line out if you don't want to create a thumbnail, change the 200 to the size you want
            }
          }
        }
      }
    }
  $i++;
  echo $endresult."<br>";
  }
}
?>
</body>
</html>

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.