function insertTestData() { $db_conn = new mysqli("localhost", "zdliu", "63859", "classicpolish168"); if ($db_conn->connect_error) { $errString = "Failed to connect to the database"; echo "<br/> {$errString} "; throw new Exception($errString); } tcCustomer::runTest($db_conn); tcVisits::runTest($db_conn); $insert1 = "INSERT INTO customers ( fname, lname, phone, email ) VALUES ( " . '"mason",' . '"you",' . '"2125187517",' . '"*****@*****.**")'; $insert2 = "INSERT INTO customers ( fname, lname, phone, email ) VALUES ( " . '"candy",' . '"liu",' . '"2125187518",' . '"*****@*****.**")'; $insert3 = "INSERT INTO customers ( fname, lname, phone, email ) VALUES ( " . '"sheryl",' . '"liu",' . '"2125187519",' . '"*****@*****.**")'; $db_conn->query($insert1); $db_conn->query($insert2); $db_conn->query($insert3); $visit1a = "INSERT INTO visits ( id, points ) VALUES ( 1, " . '10 )'; $visit1b = "INSERT INTO visits ( id, points ) VALUES ( 1, " . '14 )'; $visit2a = "INSERT INTO visits ( id, points ) VALUES ( 2, " . '30 )'; $visit2b = "INSERT INTO visits ( id, points ) VALUES ( 2, " . '24 )'; $visit2c = "INSERT INTO visits ( id, points ) VALUES ( 2, " . '14 )'; $visit3a = "INSERT INTO visits ( id, points ) VALUES ( 3, " . '4 )'; $db_conn->query($visit1a); $db_conn->query($visit1b); $db_conn->query($visit2a); $db_conn->query($visit2b); $db_conn->query($visit2c); $db_conn->query($visit3a); $db_conn->close(); }
function emailReceipt($db_conn, $id) { // get the customer information from the database $customer = tcCustomer::getCustomerById($db_conn, $id); $totalPoints = tcVisits::getTotalPointsById($db_conn, $id); $toAddr = $customer->email; $subject = "Thanks for visiting Classic Polish 168!"; $msg = ""; $header = "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $param = "-FClassicPolish168"; // populate the email body $visits = new tcVisits($id, $db_conn); $visits->initVisits(); $msg = $msg . '<html>'; $msg = $msg . '<head><title>Visit History</title></head>'; $msg = $msg . '<body>'; $msg = $msg . '<p>Dear ' . "{$customer->fname} {$customer->lname}:"; $msg = $msg . '<p>Below is a copy of your visit history and point balance for your reference.'; $msg = $msg . 'We look forward to serve you again. Have a great day!</p>'; $msg = $msg . '<table align="center" border="1">'; $msg = $msg . '<th>Date</th>'; $msg = $msg . '<th>Points</th>'; for ($i = 0; $i < count($visits->visits); ++$i) { $msg = $msg . '<tr>'; $msg = $msg . '<td align="center">' . $visits->visits[$i]->dtime . '</td>'; $msg = $msg . '<td align="right">' . $visits->visits[$i]->point . '</td>'; $msg = $msg . '</tr>'; } $msg = $msg . '<tr>'; $msg = $msg . '<td align="left"><strong>Balance:</strong></td>'; $totalPtrs = tcVisits::getTotalPointsById($db_conn, $id); $msg = $msg . '<td align="right">' . $totalPtrs . '</td>'; $msg = $msg . '</tr>'; $msg = $msg . '</table>'; $msg = $msg . '</body>'; $msg = $msg . '</html>'; if (mail($toAddr, $subject, $msg, $header, $param)) { $infoMsg = "Email sent successfully to {$customer->fname} {$customer->lname}!"; if (isset($_POST["id"])) { print $msg; print '<br/>'; print '<p align="center"><font color="green" size=20><strong>' . $infoMsg . '</strong></font></p>'; header("refresh:5; url=showdetails.php?custId=" . $id); } else { print $infoMsg; } } else { $errorMsg = "Failed to send email to {$customer->fname} {$customer->lname} with email {$customer->email}!"; if (isset($_POST["id"])) { print '<p align="center"><font color="red" size=20><strong>' . $errorMsg . '</strong></font></p>'; } else { print $errorMsg; } } }
<?php require_once "tcCustomer.php"; require_once "tcVisits.php"; // database information $DB_HOSTNAME = "localhost"; $DB_USERNAME = "******"; $DB_PASSWORD = "******"; $DB_NAME = "classicpolish168"; $TABLE_NAME = "customers"; // this is reg-exp used for querying the database $SQL_ANY_STRING = " REGEXP '[a-z]|[A-Z]*' "; // make connection to the database $db_conn = new mysqli($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DB_NAME); if ($db_conn->connect_error) { $errString = "Failed to connect to the database"; echo "<br/> {$errString} "; exit($errString); } tcCustomer::createTable($db_conn); tcVisits::createTable($db_conn); // cheat sheet: // create user 'zdliu'@'localhost' identified by 'password'; // grant all privileges on classicpolish168.* to 'zdliu'@'localhost' // $dtime = new DateTime( $result->my_datetime ); // print $dtime->format( "Y-m-d H:i:s"); // insert into visits ( id, datetime, points ) values ( 1, "2014/04/25 15:22:38", 100 );
<?php require_once "mysql_db_defs.php"; require_once "tcCustomer.php"; global $db_conn; // retrieve information from HTPP POST array $custFName = $_POST["fname"]; $custLName = $_POST["lname"]; $custPhone = $_POST["phone"]; $custEmail = $_POST["email"]; $customer = new tcCustomer($db_conn); $customer->fname = $custFName; $customer->lname = $custLName; $customer->phone = $custPhone; $customer->email = $custEmail; $customer->initCustomer();
<html> <head> <title> <?php require_once "mysql_db_defs.php"; require_once "htmlUtil.php"; require_once "tcCustomer.php"; require_once "tcVisits.php"; global $db_conn; $custId = $_GET["custId"]; $customer = tcCustomer::getCustomerById($db_conn, $custId); echo "{$customer->fname} {$customer->lname}"; ?> </title> </head> <body> <?php // display the search panel on the top showSearchPanel(); // display detailed information about the customer $customer->showDetailTable(); print '<br/>'; print '<br/>'; // this section outputs the drop down menu to add points for the visit print '<table align="center">'; print ' <tr>'; print ' <form method="post" action="addpoint.php" >'; print ' <td>'; print ' <select name="intSign">';
<?php require_once "mysql_db_defs.php"; require_once "htmlUtil.php"; require_once "tcCustomer.php"; global $db_conn; $customer = new tcCustomer($db_conn); $customer->custId = $_POST["id"]; $customer->fname = $_POST["fname"]; $customer->lname = $_POST["lname"]; $customer->phone = $_POST["phone"]; $customer->email = $_POST["email"]; // update the customer information on the database $customer->updateCustomer();