Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Sending email after insert record

Explorer ,
Sep 11, 2011 Sep 11, 2011

Hi guys, I've always pointed forms to process.php, which grabs the form fields and emails them, then redirects to thanks.php. I've now started working with dreamweaver PHP functions and if I insert a record into MySQL, the form action becomes echo $editFormAction; and the code points to process.php, but no email comes through. It ends up at thanks.php so it's still going via process.php. Anyone know why it's not working? Should I be sending the email after the insert all on the same page? thanks

TOPICS
Server side applications
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Sep 12, 2011 Sep 12, 2011

By itself, the insert record will submit back to itself and DW will place is own form action on the form. The insert code is wrapped in an IF statement which basically checks whether the page is loading for the first time, or if the form action is true andnthen execute the insert code, and redirect. You shold be able to take the email script from the process.PHP page and place it after the insert code and before the redirect. The form variables will be available to both the insert script and the

...
Translate
Community Expert ,
Sep 12, 2011 Sep 12, 2011

We will need to see the code and may need to get you editing the code.  The DW functions are good for many basic tasks when done alone, but when you start combining things it will be very beneficial for you to take learn coding and take advantage of the code hinting that DW offers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2011 Sep 12, 2011

Thanks. I didn't post the code as thought I was prob just not understanding the usual process.

<?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {   if (PHP_VERSION < 6) {     $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 users (name, companyName, userName, telephone, newsletter, reminder, password, comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",                        GetSQLValueString($_POST['fullname'], "text"),                        GetSQLValueString($_POST['hiddenCompanyName'], "text"),                        GetSQLValueString($_POST['email1'], "text"),                        GetSQLValueString($_POST['telephone'], "text"),                        GetSQLValueString($_POST['newsletter'], "text"),                        GetSQLValueString($_POST['reminder'], "text"),                        GetSQLValueString($_POST['password1'], "text"),                        GetSQLValueString($_POST['comments'], "text"));   mysql_select_db($database_test, $test);   $Result1 = mysql_query($insertSQL, $test) or die(mysql_error());   $insertGoTo = "process.php";   if (isset($_SERVER['QUERY_STRING'])) {     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";     $insertGoTo .= $_SERVER['QUERY_STRING'];   }   header(sprintf("Location: %s", $insertGoTo)); } $colname_userDets = "-1"; if (isset($_SESSION['MM_Username'])) {   $colname_userDets = $_SESSION['MM_Username']; } mysql_select_db($database_test, $test); $query_userDets = sprintf("SELECT companiesId, userName, password, name FROM companies WHERE userName = %s", GetSQLValueString($colname_userDets, "text")); $userDets = mysql_query($query_userDets, $test) or die(mysql_error()); $row_userDets = mysql_fetch_assoc($userDets); $totalRows_userDets = mysql_num_rows($userDets); ?>


Then my form on the same page contains inputs named email1, fullname, password1 etc and starts with...

<form action="<?php echo $editFormAction; ?>" name="form1" method="POST">

And process.php contains this

<?php /* Subject and Email Variables */      $emailSubject = "Registration Successful | Processed at ".strftime("%T", time());      $webMaster = xxx;      /* Gathering Data Variables */      $email1 = $_POST['email1'];      $fullname = $_POST['fullname'];      $password1 = $_POST['password1'];       $body = <<<EOD      Dear $fullname, <br> <br> Thanks for registering. Please connect to the following address and bookmark our login page in your web browser. <br> <br> Web Address:     www.xxx.com<br> <br> Your Username:     $email1 <br> Your Password:     $password1 <br> <br> <hr> <br> Thanks EOD;      $headers = "From: $email1\r\n";      $headers .= 'Cc: xxx@xxx.com' . "\r\n";      $headers .= "Content-type: text/html\r\n";      $success = mail($webMaster, $emailSubject, $body, $headers); header("Location: thanks.php"); ?>

process.php sends the email if I remove the insert record and point the form to process.php but otherwise fails to send.  Thanks again, pls let me know if you need any more code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 12, 2011 Sep 12, 2011

By itself, the insert record will submit back to itself and DW will place is own form action on the form. The insert code is wrapped in an IF statement which basically checks whether the page is loading for the first time, or if the form action is true andnthen execute the insert code, and redirect. You shold be able to take the email script from the process.PHP page and place it after the insert code and before the redirect. The form variables will be available to both the insert script and the email script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2011 Sep 12, 2011

Thank you so much. Been struggling with this for ages! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 13, 2011 Sep 13, 2011
LATEST

Did you get it working? Once you get a handle on how these scripts work in an IF statement after the form page submits back to itself you'll be able to do lots of other things in the same fashion. Before I figured this all out, I would use different pages and place the form variables in session variables to use on other pages. Not the best way to go.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines