Email Notification & MySQL Results Summary

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Email Notification & MySQL Results Summary

Post by cupaball »

Hi All:

Let me start off with my php knowledge stops at Dreamweaver. I have cs3 with the developers toolbox, but I am using Dreamweaver 8 with the native php scprit (why, because I haven't transfered my files to the new computer) Anyways I have two issues regarding the same form. The form is simple radio button form that inserts into a MySql database. What I need is the following help:

1. How can I have an e-mail sent to the admin indicating a new post to the survey? Here the code: (as you will see I have two hidden fields the email and the message)

Code: Select all

<?php require_once('../Connections/BackStabber.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "survey")) {
  $insertSQL = sprintf("INSERT INTO survey (See_it_Again, Fav_Song, Fav_Char, Fav_Scene, Comments) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['comeagain'], "text"),
                       GetSQLValueString($_POST['favsong'], "text"),
                       GetSQLValueString($_POST['char'], "text"),
                       GetSQLValueString($_POST['scene'], "text"),
                       GetSQLValueString($_POST['feebback'], "text"));

  mysql_select_db($database_BackStabber, $BackStabber);
  $Result1 = mysql_query($insertSQL, $BackStabber) or die(mysql_error());

  $insertGoTo = "iframethankyou.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_BackStabber, $BackStabber);
$query_Survey = "SELECT * FROM survey";
$Survey = mysql_query($query_Survey, $BackStabber) or die(mysql_error());
$row_Survey = mysql_fetch_assoc($Survey);
$totalRows_Survey = mysql_num_rows($Survey);
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
body {
scrollbar-base-color: #FFFFFF;
scrollbar-arrow-color: #FCFCFC;
scrollbar-3dlight-color: #7c1818;
scrollbar-darkshadow-color: #7C1818;
scrollbar-face-color: #7C1818;
scrollbar-highlight-color: #7c1818;
scrollbar-shadow-color: #7c1818;
scrollbar-track-color: #FFFFFF;
}
</style>
<style type="text/css">
<!--
body,td,th {
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #333333;
}
.prograjm {
	float: right;
	padding-bottom: 0px;
	padding-right: 5px;
}
-->
</style>
</head>

<body>
<p>&nbsp;</p>
<table width="380" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p><strong>New Boundaries Productions is geared to providing you with  the best entertainment possible.&nbsp; We want  to hear from you.!</strong></p>
      <form id="survey1" name="survey" method="POST" action="<?php echo $editFormAction; ?>">
        1. 
      Would you come see the play again?<br />
        <label>
        <input name="comeagain" type="radio" value="yes" checked="checked" />
        Yes</label>
        <label>
        <br />
        <input name="comeagain" type="radio" value="no" />
        No</label>
        <br />
        <br />
        2.
        What was your favorite song in the play?<br />
        <label>
        <input name="favsong" type="radio" value="massage" checked="checked" />
        Massage</label>
        <br />
        <label>
        <input name="favsong" type="radio" value="nowon" />
        From Now On</label>
        <br />
        <label>
        <input name="favsong" type="radio" value="yourname" />
        I Call Your Name</label>
        <br />
        <br />
        3.
        Who was your favorite charcter?<br />
        <label>
        <input name="char" type="radio" value="keith" checked="checked" />
        Keith</label>
        <br />
        <label>
        <input name="char" type="radio" value="jade" />
        Jade</label> 
        <br />
        <label>
        <input name="char" type="radio" value="shelia" />
        Sheila</label>
        <br />
        <label>
        <input name="char" type="radio" value="kathy" />
        Kathy</label>
        <br />
        <label>
        <input name="char" type="radio" value="dena" />
        Dena</label>
        <br />
        <label>
        <input name="char" type="radio" value="aaron" />
        Aaron</label>
        <br />
        <br />
        4.
        What was your favorite scene?<br />
        <label>
        <input name="scene" type="radio" value="salon" checked="checked" />
        The Salon</label>
        <br />
        <label>
        <input name="scene" type="radio" value="jadeexplodes" />
        Jade Explodes</label>
        <br />
        <label>
        <input name="scene" type="radio" value="ending" />
        The Ending</label>
        <br />
        <br />
        5.
        Please provide any additional feedback regarding the play:<br />
        <label>
        <textarea name="feebback" cols="35" rows="5" id="feebback"></textarea>
        </label> 
        <p align="right">
          <input name="email" type="hidden" id="email" value="maleftball@google.com">
          <input name="message" type="hidden" id="email" value="Youve Got Feedback" />
        <input name="image" type="image" value="Submit" src="images/submit.jpg" alt="Submit" align="left" />&nbsp;</p>
          <input type="hidden" name="MM_insert" value="survey">
      </form>      
      <p><strong></strong></p></td>
  </tr>
</table>
</body>
</html><?php
mysql_free_result($Survey);
?>
and two on my results page I can only list the results but I want to summarize by them data. Example - If the column "Will come again" has 4 yes and 2 no's, I want it to show
Yes - 4
No - 2

The Code

Code: Select all

<?php require_once('../Connections/BackStabber.php'); ?>
<?php
$maxRows_RecordCount = 10;
$pageNum_RecordCount = 0;
if (isset($_GET['pageNum_RecordCount'])) {
  $pageNum_RecordCount = $_GET['pageNum_RecordCount'];
}
$startRow_RecordCount = $pageNum_RecordCount * $maxRows_RecordCount;

mysql_select_db($database_BackStabber, $BackStabber);
$query_RecordCount = "SELECT * FROM survey ORDER BY ID ASC";
$query_limit_RecordCount = sprintf("%s LIMIT %d, %d", $query_RecordCount, $startRow_RecordCount, $maxRows_RecordCount);
$RecordCount = mysql_query($query_limit_RecordCount, $BackStabber) or die(mysql_error());
$row_RecordCount = mysql_fetch_assoc($RecordCount);

if (isset($_GET['totalRows_RecordCount'])) {
  $totalRows_RecordCount = $_GET['totalRows_RecordCount'];
} else {
  $all_RecordCount = mysql_query($query_RecordCount);
  $totalRows_RecordCount = mysql_num_rows($all_RecordCount);
}
$totalPages_RecordCount = ceil($totalRows_RecordCount/$maxRows_RecordCount)-1;
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
body {
scrollbar-base-color: #FFFFFF;
scrollbar-arrow-color: #FCFCFC;
scrollbar-3dlight-color: #7c1818;
scrollbar-darkshadow-color: #7C1818;
scrollbar-face-color: #7C1818;
scrollbar-highlight-color: #7c1818;
scrollbar-shadow-color: #7c1818;
scrollbar-track-color: #FFFFFF;
}
</style>
<style type="text/css">
<!--
body,td,th {
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #333333;
}
.prograjm {
	float: right;
	padding-bottom: 0px;
	padding-right: 5px;
}
-->
</style>
</head>

<body>
<table width="380" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" valign="top"><p><strong>Feedback Result</strong>s<br>
    Total Records <?php echo $totalRows_RecordCount ?> </p>
      <table border="1" cellpadding="5" cellspacing="0" bordercolor="#666666">
        <tr>
          <td><strong>Will See It Again </strong></td>
          <td><strong>Favorite Song</strong></td>
          <td><strong>Favorite Character</strong></td>
          <td><strong>Favorite Scene</strong></td>
          <td><strong>Comments</strong></td>
        </tr>
        <?php do { ?>
        <tr>
          <td><?php echo $row_RecordCount['See_it_Again']; ?></td>
          <td><?php echo $row_RecordCount['Fav_Song']; ?></td>
          <td><?php echo $row_RecordCount['Fav_Char']; ?></td>
          <td><?php echo $row_RecordCount['Fav_Scene']; ?></td>
          <td><?php echo $row_RecordCount['Comments']; ?></td>
        </tr>
        <?php } while ($row_RecordCount = mysql_fetch_assoc($RecordCount)); ?>
      </table>
      </td>
  </tr>
</table>
</body>
</html><?php
mysql_free_result($RecordCount);

mysql_free_result($RecordCount);
?>
Any help would be great!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

For your first question, when the insert is done and is cleared (meaning you completed all error checking) send the email at the time. Simple enough.

As for the second, a var_dump() of your $_POST array might should you what you need to be able to do what you want.

PS
Let me start off with my php knowledge stops at Dreamweaver.
Literally made me chuckle out loud.
Post Reply