Jump to content

Recommended Posts

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:

[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);
?>

[/code]
  • 2 months later...
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:
[url=http://support.microsoft.com/kb/312839/en-us]http://support.microsoft.com/kb/312839/en-us[/url]

Or you could configure SQL Mail, though this requires a MAPI profile from memory.
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.