Jump to content


Photo

How do I get a copy of submitted database info via email?


  • Please log in to reply
1 reply to this topic

#1 djpassion

djpassion
  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationScottish Highlands

Posted 17 July 2006 - 02:35 PM

Hi i am trying to create a form whereby the information gets stored on the database and also displays the database info on the page. But I would also like to get a copy of what is submitted to my email address. Is this possible?. Here is my code:

<?php require_once('Connections/mySql.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 textform (name, email, address, age) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['age'], "int"));

  mysql_select_db($database_mySql, $mySql);
  $Result1 = mysql_query($insertSQL, $mySql) or die(mysql_error());
}

$maxRows_test = 5;
$pageNum_test = 0;
if (isset($_GET['pageNum_test'])) {
  $pageNum_test = $_GET['pageNum_test'];
}
$startRow_test = $pageNum_test * $maxRows_test;

mysql_select_db($database_mySql, $mySql);
$query_test = "SELECT * FROM textform ORDER BY name ASC";
$query_limit_test = sprintf("%s LIMIT %d, %d", $query_test, $startRow_test, $maxRows_test);
$test = mysql_query($query_limit_test, $mySql) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);

if (isset($_GET['totalRows_test'])) {
  $totalRows_test = $_GET['totalRows_test'];
} else {
  $all_test = mysql_query($query_test);
  $totalRows_test = mysql_num_rows($all_test);
}
$totalPages_test = ceil($totalRows_test/$maxRows_test)-1;
?>
<?php

  // if submitted form process and send mail
  if ($REQUEST_METHOD == "POST") {

    // just to be safe I strip out HTML tags
    $name = strip_tags($name);
    $email = strip_tags($email);
    $address = strip_tags($address);
	$age = strip_tags($age);

    // set the variables
    // replace $me@mysite.com with your email address
    $sendto = "$******@hotmail.co.uk";
    $subject = "does this work";
    $message = "$name, $email\n$age\n\n$address";

    // send the email
    mail($sendto, $subject, $message);

  }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
    // if submitted form display sent message
    if ($REQUEST_METHOD=="POST") {
        echo("<p><b>Thank you for your feedback. The following message was sent:</b></p>\n");
        echo("<blockquote><pre>\n");
        echo("$message");
        echo("</pre></blockquote>");
    }
    // if not display form
    else {
?>
<form method="post" name="form1" action="<?php echo("$script_name"); ?>">
  <table>
    <tr valign="baseline">
      <td nowrap align="right">Name:</td>
      <td><input type="text" name="name" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address:</td>
      <td><input type="text" name="address" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Age:</td>
      <td><input name="age" type="text" value="" size="2" maxlength="2"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>

<?php } ?>

<?php do { ?>
  <p>Name: <?php echo $row_test['name']; ?></p>
  <p>Email: <?php echo $row_test['email']; ?></p>
  <p>Address: <?php echo $row_test['address']; ?></p>
  <p>age: <?php echo $row_test['age']; ?></p>
  <?php } while ($row_test = mysql_fetch_assoc($test)); ?>

  </body>
</html>
<?php
mysql_free_result($test);
?>


Every morning is the dawn of a new error

#2 GeoffOs

GeoffOs
  • Members
  • PipPip
  • Member
  • 24 posts
  • LocationCheshire, England

Posted 05 October 2006 - 07:29 PM

Where is the SQL Server Located?
Can you use extended stored Procedures. If so you could use a stored proc to send an email.

Have a look here:
http://support.micro...kb/312839/en-us

Or you could configure SQL Mail, though this requires a MAPI profile from memory.
Beyond a critical point within a finite space, freedom diminishes as numbers increase....[br]The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."[br]-- Frank Herbert - Dune




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users