Send e-mail when a user adds a database value from PHP Site
My company uses a website that allows us to create part numbers and if a
part number doesn't exist for what the customer is trying to build
(pressure sensors), the sales representative can add this value to the
database. The form they use is a multidimensional array as follows:
$arr_attributes = array (
array ('series', 'Series', '<i>Series</i>', '<b
class="attribute">00</b>00.00000.000000<span
class="specialdigit">0</span>'),
array ('drawing', 'Drawing', '<i>Drawing</i>', '00<b
class="attribute">00</b>.00000.000000<span
class="specialdigit">0</span>'),
array ('pressure_range', 'Pressure Range', '<i>0 - 15</i>', '0000.<b
class="attribute">000</b>00.000000<span class="specialdigit">0</span>'),
array ('pressure_type', 'Pressure Type', '<i>PSI</i>', '0000.000<b
class="attribute">00</b>.000000<span class="specialdigit">0</span>'),
array ('output_type', 'Output Type', '<i>voltage</i>', '0000.00000.<b
class="attribute">00</b>0000<span class="specialdigit">0</span>'),
array ('termination', 'Electrical Termination', '<i>termination</i>',
'0000.00000.00<b class="attribute">00</b>00<span
class="specialdigit">0</span>'),
array ('cable_length', 'Cable Length', '<i>100 <span
class="specialdigit">(feet assumed)</span></i>', '0000.00000.0000<b
class="attribute">00</b><b class="specialdigit">0</b>'),
array ('optional', 'Optional', '<i>Option</i>', '0000.00000.000000<span
class="specialdigit">0</span><b class="attribute">.00<b
class="specialdigit">0</b></b>')
);
?>
A separate page on the site references this array as follows:
if (isset($_POST['table']) && (isset($_POST['value']))) {
$str_table = trim($_POST['table']);
$str_value = trim($_POST['value']);
if (empty($arr_errors)) {
require_once 'include/database.inc.php'; // Class used to add an
attribute to the database
$obj_database = New Database; // Create the 'Database' class object
$obj_database->table = $str_table;
$obj_database->value = $str_value;
if ($obj_database->check()) { // Does the attribute exist?
if ($obj_database->add()) { // Add attribute to the database
echo "<p class=\"message\">The attribute was successfully
added to the database!";
} else {
$arr_errors['102'] = "Error code 102: Unknown error while
processing the attribute!";
}
} else {
$arr_errors['103'] = "Error 103: An attribute with this value
already exists in the database!";
}
}
} elseif (isset($_POST['submit'])) {
$arr_errors['104'] = "Error 104: All values were not provided! Please
select an attribute type and give it a value.";
}
if (!empty($arr_errors)) {
foreach ($arr_errors as $error) {
echo "<p class=\"error\">" . $error . "</p>\n";
}
}
If a sales rep adds a value to pressure type/output type/electrical
termination/option I want to be notified via email. I haven't been able to
figure out where to put the code and how to code it!
Thanks all!
No comments:
Post a Comment