Jump to content

Form to insert into DB and send email problem


TrevMac

Recommended Posts

Hi all,

 

Wonder if any of you know how to resolve this:

 

I have a form that I have created in DW8 that inserts the info into a database. This works fine. I would like to add the facility for the form to also send an email to 2 addresses with the exact same data that is entered into the DB.

 

I am pretty new to PHP so if you could make your reply pretty idiot proof then it would help me a lot.

 

Here is the PHP code as it appears in my form:

 

<?php require_once('Connections/mysite.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO landrequired (firstName, lastName, address1, address2, postcode, telWork, telHome, telMobile, email, location, approxSize, currentUse, localAuth, planPerm, approached, comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                      GetSQLValueString($_POST['firstName'], "text"),

                      GetSQLValueString($_POST['lastName'], "text"),

                      GetSQLValueString($_POST['address1'], "text"),

                      GetSQLValueString($_POST['address2'], "text"),

                      GetSQLValueString($_POST['postcode'], "text"),

                      GetSQLValueString($_POST['telWork'], "text"),

                      GetSQLValueString($_POST['telHome'], "text"),

                      GetSQLValueString($_POST['telMobile'], "text"),

                      GetSQLValueString($_POST['email'], "text"),

                      GetSQLValueString($_POST['location'], "text"),

                      GetSQLValueString($_POST['approxSize'], "text"),

                      GetSQLValueString($_POST['currentUse'], "text"),

                      GetSQLValueString($_POST['localAuth'], "text"),

                      GetSQLValueString($_POST['planPerm'], "text"),

                      GetSQLValueString($_POST['approached'], "text"),

                      GetSQLValueString($_POST['comments'], "text"));

 

  mysql_select_db($database_myDB, $myDB);

  $Result1 = mysql_query($insertSQL, $myDB) or die(mysql_error());

 

 

  $insertGoTo = "thankyou.php";

if (isset($_SERVER['QUERY_STRING'])) {

  $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

$insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

?>

 

HTML follows with form for input.

 

Any answers would be much appreciated. Thanx in advance.

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.