\ No newline at end of file
diff --git a/Ch01/header-for-template.php b/Ch01/header-for-template.php
new file mode 100644
index 0000000..0a925b3
--- /dev/null
+++ b/Ch01/header-for-template.php
@@ -0,0 +1,7 @@
+
+
+
+
+
This is the header
+
+
\ No newline at end of file
diff --git a/Ch01/header.php b/Ch01/header.php
new file mode 100644
index 0000000..167eeb2
--- /dev/null
+++ b/Ch01/header.php
@@ -0,0 +1,13 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch01/index.php b/Ch01/index.php
new file mode 100644
index 0000000..e577826
--- /dev/null
+++ b/Ch01/index.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
\ No newline at end of file
diff --git a/Ch01/logo.jpg b/Ch01/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch01/logo.jpg differ
diff --git a/Ch01/menu.php b/Ch01/menu.php
new file mode 100644
index 0000000..11f463b
--- /dev/null
+++ b/Ch01/menu.php
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file
diff --git a/Ch01/nav.txt b/Ch01/nav.txt
new file mode 100644
index 0000000..5be2e9f
--- /dev/null
+++ b/Ch01/nav.txt
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Project 1 incomplete
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ch01/password-thanks.php b/Ch01/password-thanks.php
new file mode 100644
index 0000000..3f516ea
--- /dev/null
+++ b/Ch01/password-thanks.php
@@ -0,0 +1,45 @@
+
+
+
+ Password Change Thanks
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Thank you for changing your password
+On the Home Page, you will now be able to login with your new password.
+
+
+
+
+
+
+
+
+
diff --git a/Ch01/process-change-password.php b/Ch01/process-change-password.php
new file mode 100644
index 0000000..f40f461
--- /dev/null
+++ b/Ch01/process-change-password.php
@@ -0,0 +1,110 @@
+
+ You could not change password due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Invalid email address/password combination.
+ $errorstring = 'Error! ';
+ $errorstring .= 'The email address and/or password do not match those on file.';
+ $errorstring .= " Please try again.";
+ echo "
$errorstring
";
+} }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors.
+ //header ("location: register-page.php");
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
+
+
+
+
+
+
+
diff --git a/Ch01/process-register-page.php b/Ch01/process-register-page.php
new file mode 100644
index 0000000..1108103
--- /dev/null
+++ b/Ch01/process-register-page.php
@@ -0,0 +1,85 @@
+
+";
+ $errorstring .= "System Error You could not be registered due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ mysqli_close($dbcon); // Close the database connection.
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ }
+ catch(Exception $e) // We finally handle any problems here #12
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors. #13
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
\ No newline at end of file
diff --git a/Ch01/register-page.php b/Ch01/register-page.php
new file mode 100644
index 0000000..8c9002a
--- /dev/null
+++ b/Ch01/register-page.php
@@ -0,0 +1,109 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+On the Home Page, you will now be able to login and add new quotes to the message board.
+
+
+
+
+
+
+
+
+
diff --git a/Ch01/register-view-users.php b/Ch01/register-view-users.php
new file mode 100644
index 0000000..55fcc35
--- /dev/null
+++ b/Ch01/register-view-users.php
@@ -0,0 +1,86 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch01/simpledb.sql b/Ch01/simpledb.sql
new file mode 100644
index 0000000..6e6c6a5
--- /dev/null
+++ b/Ch01/simpledb.sql
@@ -0,0 +1,74 @@
+-- phpMyAdmin SQL Dump
+-- version 4.7.4
+-- https://www.phpmyadmin.net/
+--
+-- Host: 127.0.0.1
+-- Generation Time: Jul 27, 2018 at 06:37 PM
+-- Server version: 10.1.28-MariaDB
+-- PHP Version: 7.1.11
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET AUTOCOMMIT = 0;
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Database: `simpledb`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `users`
+--
+
+CREATE TABLE `users` (
+ `userid` mediumint(6) UNSIGNED NOT NULL,
+ `first_name` varchar(30) NOT NULL,
+ `last_name` varchar(40) NOT NULL,
+ `email` varchar(60) NOT NULL,
+ `password` char(60) NOT NULL,
+ `registration_date` datetime NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
+-- Dumping data for table `users`
+--
+
+INSERT INTO `users` (`userid`, `first_name`, `last_name`, `email`, `password`, `registration_date`) VALUES
+(1, 'Steve', 'Johnson', 'sjohnson@sjohnson.com', '$2y$10$lEmRKPYfu/Nb6ECtbmp7YOuIZeZDYuCnZKRmEBnQ6nRHDKJHdEgMK', '2018-04-26 15:11:58'),
+(2, 'Mike', 'Rosolt', 'mrosolf@someplace.com', '$2y$10$9lXam45bwNHu4/zbu5FdXuW243F1R0GkQBDJr/juvV8wYr6lMZbau', '2018-04-28 15:15:32'),
+(3, 'Tweedle', 'Dee-Deest', 'tdeedeest@themail.com', '$2y$10$.ewnSKbbeP6lSI4UF0BasOTnDyLzBH8mwcDM3wEM1hzoJAXYz2doK', '2018-04-28 15:17:29'),
+(4, 'Annie', 'Versary', 'aversary@outcook.com', '$2y$10$5yz6IiFq/uZR4VdacjVRbOWTIA5tZCSLZ975mGZCoas3UHMMojN46', '2018-04-28 15:18:17'),
+(5, 'Charley', 'Farnsbarns', 'cfransnarns@outcook.com', '$2y$10$WFX630.YbR5WQcYNBnMMueIbjIbo5.C6aDkUKVUfXBC1oNrqasmWa', '2018-04-28 15:19:50');
+
+--
+-- Indexes for dumped tables
+--
+
+--
+-- Indexes for table `users`
+--
+ALTER TABLE `users`
+ ADD PRIMARY KEY (`userid`);
+
+--
+-- AUTO_INCREMENT for dumped tables
+--
+
+--
+-- AUTO_INCREMENT for table `users`
+--
+ALTER TABLE `users`
+ MODIFY `userid` mediumint(6) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/Ch01/template.php b/Ch01/template.php
new file mode 100644
index 0000000..efdbacb
--- /dev/null
+++ b/Ch01/template.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
+
+
+
+
+
+
+
+
+
diff --git a/Ch01/verify.js b/Ch01/verify.js
new file mode 100644
index 0000000..b5a9501
--- /dev/null
+++ b/Ch01/verify.js
@@ -0,0 +1,12 @@
+function checked() {
+ if (document.getElementById('password1').value ==
+ document.getElementById('password2').value) {
+ document.getElementById('message').style.color = 'green';
+ document.getElementById('message').innerHTML = 'Passwords match';
+ return true;
+ } else {
+ document.getElementById('message').style.color = 'red';
+ document.getElementById('message').innerHTML = 'Passwords do not match';
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/Ch02/simpledb/change-password.php b/Ch02/simpledb/change-password.php
new file mode 100644
index 0000000..1719254
--- /dev/null
+++ b/Ch02/simpledb/change-password.php
@@ -0,0 +1,101 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ch02/simpledb/header-for-template.php b/Ch02/simpledb/header-for-template.php
new file mode 100644
index 0000000..0a925b3
--- /dev/null
+++ b/Ch02/simpledb/header-for-template.php
@@ -0,0 +1,7 @@
+
+
+
+
+
This is the header
+
+
\ No newline at end of file
diff --git a/Ch02/simpledb/header.php b/Ch02/simpledb/header.php
new file mode 100644
index 0000000..167eeb2
--- /dev/null
+++ b/Ch02/simpledb/header.php
@@ -0,0 +1,13 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch02/simpledb/index.php b/Ch02/simpledb/index.php
new file mode 100644
index 0000000..e577826
--- /dev/null
+++ b/Ch02/simpledb/index.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
\ No newline at end of file
diff --git a/Ch02/simpledb/logo.jpg b/Ch02/simpledb/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch02/simpledb/logo.jpg differ
diff --git a/Ch02/simpledb/menu.php b/Ch02/simpledb/menu.php
new file mode 100644
index 0000000..11f463b
--- /dev/null
+++ b/Ch02/simpledb/menu.php
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file
diff --git a/Ch02/simpledb/nav.txt b/Ch02/simpledb/nav.txt
new file mode 100644
index 0000000..5be2e9f
--- /dev/null
+++ b/Ch02/simpledb/nav.txt
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Project 1 incomplete
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ch02/simpledb/password-thanks.php b/Ch02/simpledb/password-thanks.php
new file mode 100644
index 0000000..3f516ea
--- /dev/null
+++ b/Ch02/simpledb/password-thanks.php
@@ -0,0 +1,45 @@
+
+
+
+ Password Change Thanks
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Thank you for changing your password
+On the Home Page, you will now be able to login with your new password.
+
+
+
+
+
+
+
+
+
diff --git a/Ch02/simpledb/process-change-password.php b/Ch02/simpledb/process-change-password.php
new file mode 100644
index 0000000..f40f461
--- /dev/null
+++ b/Ch02/simpledb/process-change-password.php
@@ -0,0 +1,110 @@
+
+ You could not change password due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Invalid email address/password combination.
+ $errorstring = 'Error! ';
+ $errorstring .= 'The email address and/or password do not match those on file.';
+ $errorstring .= " Please try again.";
+ echo "
$errorstring
";
+} }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors.
+ //header ("location: register-page.php");
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
+
+
+
+
+
+
+
diff --git a/Ch02/simpledb/process-register-page.php b/Ch02/simpledb/process-register-page.php
new file mode 100644
index 0000000..1108103
--- /dev/null
+++ b/Ch02/simpledb/process-register-page.php
@@ -0,0 +1,85 @@
+
+";
+ $errorstring .= "System Error You could not be registered due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ mysqli_close($dbcon); // Close the database connection.
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ }
+ catch(Exception $e) // We finally handle any problems here #12
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors. #13
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
\ No newline at end of file
diff --git a/Ch02/simpledb/register-page.php b/Ch02/simpledb/register-page.php
new file mode 100644
index 0000000..8c9002a
--- /dev/null
+++ b/Ch02/simpledb/register-page.php
@@ -0,0 +1,109 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+On the Home Page, you will now be able to login and add new quotes to the message board.
+
+
+
+
+
+
+
+
+
diff --git a/Ch02/simpledb/register-view-users.php b/Ch02/simpledb/register-view-users.php
new file mode 100644
index 0000000..55fcc35
--- /dev/null
+++ b/Ch02/simpledb/register-view-users.php
@@ -0,0 +1,86 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch02/simpledb/simpledb.sql b/Ch02/simpledb/simpledb.sql
new file mode 100644
index 0000000..6e6c6a5
--- /dev/null
+++ b/Ch02/simpledb/simpledb.sql
@@ -0,0 +1,74 @@
+-- phpMyAdmin SQL Dump
+-- version 4.7.4
+-- https://www.phpmyadmin.net/
+--
+-- Host: 127.0.0.1
+-- Generation Time: Jul 27, 2018 at 06:37 PM
+-- Server version: 10.1.28-MariaDB
+-- PHP Version: 7.1.11
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET AUTOCOMMIT = 0;
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Database: `simpledb`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `users`
+--
+
+CREATE TABLE `users` (
+ `userid` mediumint(6) UNSIGNED NOT NULL,
+ `first_name` varchar(30) NOT NULL,
+ `last_name` varchar(40) NOT NULL,
+ `email` varchar(60) NOT NULL,
+ `password` char(60) NOT NULL,
+ `registration_date` datetime NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
+-- Dumping data for table `users`
+--
+
+INSERT INTO `users` (`userid`, `first_name`, `last_name`, `email`, `password`, `registration_date`) VALUES
+(1, 'Steve', 'Johnson', 'sjohnson@sjohnson.com', '$2y$10$lEmRKPYfu/Nb6ECtbmp7YOuIZeZDYuCnZKRmEBnQ6nRHDKJHdEgMK', '2018-04-26 15:11:58'),
+(2, 'Mike', 'Rosolt', 'mrosolf@someplace.com', '$2y$10$9lXam45bwNHu4/zbu5FdXuW243F1R0GkQBDJr/juvV8wYr6lMZbau', '2018-04-28 15:15:32'),
+(3, 'Tweedle', 'Dee-Deest', 'tdeedeest@themail.com', '$2y$10$.ewnSKbbeP6lSI4UF0BasOTnDyLzBH8mwcDM3wEM1hzoJAXYz2doK', '2018-04-28 15:17:29'),
+(4, 'Annie', 'Versary', 'aversary@outcook.com', '$2y$10$5yz6IiFq/uZR4VdacjVRbOWTIA5tZCSLZ975mGZCoas3UHMMojN46', '2018-04-28 15:18:17'),
+(5, 'Charley', 'Farnsbarns', 'cfransnarns@outcook.com', '$2y$10$WFX630.YbR5WQcYNBnMMueIbjIbo5.C6aDkUKVUfXBC1oNrqasmWa', '2018-04-28 15:19:50');
+
+--
+-- Indexes for dumped tables
+--
+
+--
+-- Indexes for table `users`
+--
+ALTER TABLE `users`
+ ADD PRIMARY KEY (`userid`);
+
+--
+-- AUTO_INCREMENT for dumped tables
+--
+
+--
+-- AUTO_INCREMENT for table `users`
+--
+ALTER TABLE `users`
+ MODIFY `userid` mediumint(6) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/Ch02/simpledb/template.php b/Ch02/simpledb/template.php
new file mode 100644
index 0000000..efdbacb
--- /dev/null
+++ b/Ch02/simpledb/template.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
+
+
+
+
+
+
+
+
+
diff --git a/Ch02/simpledb/verify.js b/Ch02/simpledb/verify.js
new file mode 100644
index 0000000..b5a9501
--- /dev/null
+++ b/Ch02/simpledb/verify.js
@@ -0,0 +1,12 @@
+function checked() {
+ if (document.getElementById('password1').value ==
+ document.getElementById('password2').value) {
+ document.getElementById('message').style.color = 'green';
+ document.getElementById('message').innerHTML = 'Passwords match';
+ return true;
+ } else {
+ document.getElementById('message').style.color = 'red';
+ document.getElementById('message').innerHTML = 'Passwords do not match';
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/Ch03/login/admin-page.php b/Ch03/login/admin-page.php
new file mode 100644
index 0000000..e4ccc1d
--- /dev/null
+++ b/Ch03/login/admin-page.php
@@ -0,0 +1,57 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Administration Page
+
You have permission to:
+
■Edit and Delete a record
+
■Use the View Members button to page through all the members
+
■Use the Search button to locate a particular member
+
■Use the New Password button to change your password.
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch03/login/admin-view-users.php b/Ch03/login/admin-view-users.php
new file mode 100644
index 0000000..0da160c
--- /dev/null
+++ b/Ch03/login/admin-view-users.php
@@ -0,0 +1,93 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch03/login/admin_view_users.php b/Ch03/login/admin_view_users.php
new file mode 100644
index 0000000..0da160c
--- /dev/null
+++ b/Ch03/login/admin_view_users.php
@@ -0,0 +1,93 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch03/login/change-password.php b/Ch03/login/change-password.php
new file mode 100644
index 0000000..0e6f68c
--- /dev/null
+++ b/Ch03/login/change-password.php
@@ -0,0 +1,101 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ch03/login/header-admin.php b/Ch03/login/header-admin.php
new file mode 100644
index 0000000..2a2ab7d
--- /dev/null
+++ b/Ch03/login/header-admin.php
@@ -0,0 +1,18 @@
+
+
\ No newline at end of file
diff --git a/Ch03/login/header-thanks.php b/Ch03/login/header-thanks.php
new file mode 100644
index 0000000..b3587a4
--- /dev/null
+++ b/Ch03/login/header-thanks.php
@@ -0,0 +1,10 @@
+
+
diff --git a/Ch03/login/header.php b/Ch03/login/header.php
new file mode 100644
index 0000000..92bb26a
--- /dev/null
+++ b/Ch03/login/header.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch03/login/images/polo.png b/Ch03/login/images/polo.png
new file mode 100644
index 0000000..bca2bd2
Binary files /dev/null and b/Ch03/login/images/polo.png differ
diff --git a/Ch03/login/index.php b/Ch03/login/index.php
new file mode 100644
index 0000000..e577826
--- /dev/null
+++ b/Ch03/login/index.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
+
diff --git a/Ch03/login/login-header.php b/Ch03/login/login-header.php
new file mode 100644
index 0000000..9602ddc
--- /dev/null
+++ b/Ch03/login/login-header.php
@@ -0,0 +1,13 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch03/login/login.php b/Ch03/login/login.php
new file mode 100644
index 0000000..491873e
--- /dev/null
+++ b/Ch03/login/login.php
@@ -0,0 +1,83 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
diff --git a/Ch03/login/logindb.sql b/Ch03/login/logindb.sql
new file mode 100644
index 0000000..c3466dc
--- /dev/null
+++ b/Ch03/login/logindb.sql
@@ -0,0 +1,78 @@
+-- phpMyAdmin SQL Dump
+-- version 4.7.4
+-- https://www.phpmyadmin.net/
+--
+-- Host: 127.0.0.1
+-- Generation Time: May 17, 2018 at 11:58 PM
+-- Server version: 10.1.28-MariaDB
+-- PHP Version: 7.1.11
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET AUTOCOMMIT = 0;
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Database: `logindb`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `users`
+--
+
+CREATE TABLE `users` (
+ `userid` mediumint(6) UNSIGNED NOT NULL,
+ `first_name` varchar(30) NOT NULL,
+ `last_name` varchar(40) NOT NULL,
+ `email` varchar(60) NOT NULL,
+ `password` char(60) NOT NULL,
+ `registration_date` datetime NOT NULL,
+ `user_level` tinyint(1) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
+-- Dumping data for table `users`
+--
+
+INSERT INTO `users` (`userid`, `first_name`, `last_name`, `email`, `password`, `registration_date`, `user_level`) VALUES
+(20, 'Mike', 'Rosoft', 'miker@myisp.com', '$2y$10$VWtLxXTE1ohO1pQJ87tnGeBB1MNfkQ3V87/HIGdanmKhqflRIQEH2', '2018-05-17 17:33:49', 0),
+(21, 'Olive', 'Branch', 'obranch@myisp.com.uk', '$2y$10$aAdvrMiVcEFqRn9ISLoy6uEwS.FesiTQZ.IdsHGc/xSi2x.wkuaZ2', '2018-05-17 17:35:21', 0),
+(22, 'Frank', 'Insence', 'finsence@myisp.net', '$2y$10$0WbSaI3w.9KjkE28L7ZeN.jEPKvsPLIwRg01M6XkRtWvZkOWaT3R6', '2018-05-17 17:36:46', 0),
+(23, 'Annie', 'Versary', 'aversary@myisp.com', '$2y$10$HpUHsg0yoIy08d4./p/tM.ZLOnZ3RLGTb7YjqMEuzwb2yBpEguB9O', '2018-05-17 17:37:47', 0),
+(24, 'Terry', 'Fide', 'tfide@myisp.de', '$2y$10$Gh0nTJPXxUkZAKCkOeVC8O8jv3rJ6ZLXrEJ8szvgqDgBxb1F8uVSa', '2018-05-17 17:54:39', 0),
+(25, 'Rose', 'Bush', 'rbush@myisp.co.uk', '$2y$10$cASUiiV3w3cKWoaxH0tfmeV7IwXy2fUNJT6lQIdBbUZePmtPY/Wo2', '2018-05-17 17:55:38', 0),
+(26, 'James', 'Smith', 'jsmith@myisp.co.uk', '$2y$10$pp/Gv2tvaTUlfPKVRb/tSu/25N7mhvj7h2ybRANEvS.I2xg/99wM6', '2018-05-17 17:57:11', 0),
+(27, 'Jack', 'Smith', 'jsmith@outcook.com', '$2y$10$GXDlk.GkgdWmPRTUDCb.F.kqD.8dwkH93s0p/g1f0fnK27Z849Ry2', '2018-05-17 17:58:14', 1);
+
+--
+-- Indexes for dumped tables
+--
+
+--
+-- Indexes for table `users`
+--
+ALTER TABLE `users`
+ ADD PRIMARY KEY (`userid`);
+
+--
+-- AUTO_INCREMENT for dumped tables
+--
+
+--
+-- AUTO_INCREMENT for table `users`
+--
+ALTER TABLE `users`
+ MODIFY `userid` mediumint(6) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/Ch03/login/logo.jpg b/Ch03/login/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch03/login/logo.jpg differ
diff --git a/Ch03/login/logout.php b/Ch03/login/logout.php
new file mode 100644
index 0000000..d8abea1
--- /dev/null
+++ b/Ch03/login/logout.php
@@ -0,0 +1,18 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch03/login/members-page.php b/Ch03/login/members-page.php
new file mode 100644
index 0000000..e6252d1
--- /dev/null
+++ b/Ch03/login/members-page.php
@@ -0,0 +1,61 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Member's Page
+
The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+
+
Special offers to members only.
+
T-Shirts 10.00
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch03/login/mysqli_connect.php b/Ch03/login/mysqli_connect.php
new file mode 100644
index 0000000..13b2614
--- /dev/null
+++ b/Ch03/login/mysqli_connect.php
@@ -0,0 +1,11 @@
+
+ Home
+
+
\ No newline at end of file
diff --git a/Ch03/login/password-header.php b/Ch03/login/password-header.php
new file mode 100644
index 0000000..e6fc6c8
--- /dev/null
+++ b/Ch03/login/password-header.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch03/login/process-change-password.php b/Ch03/login/process-change-password.php
new file mode 100644
index 0000000..f40f461
--- /dev/null
+++ b/Ch03/login/process-change-password.php
@@ -0,0 +1,110 @@
+
+ You could not change password due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Invalid email address/password combination.
+ $errorstring = 'Error! ';
+ $errorstring .= 'The email address and/or password do not match those on file.';
+ $errorstring .= " Please try again.";
+ echo "
$errorstring
";
+} }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors.
+ //header ("location: register-page.php");
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
+
+
+
+
+
+
+
diff --git a/Ch03/login/process-login.php b/Ch03/login/process-login.php
new file mode 100644
index 0000000..e014b3f
--- /dev/null
+++ b/Ch03/login/process-login.php
@@ -0,0 +1,83 @@
+ The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (!empty($errors)) IF.
+mysqli_stmt_free_result($q);
+mysqli_stmt_close($q);
+}
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+} // no else to allow user to enter values
+?>
\ No newline at end of file
diff --git a/Ch03/login/process-register-page.php b/Ch03/login/process-register-page.php
new file mode 100644
index 0000000..777059b
--- /dev/null
+++ b/Ch03/login/process-register-page.php
@@ -0,0 +1,85 @@
+";
+ $errorstring .= "System Error You could not be registered due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ mysqli_close($dbcon); // Close the database connection.
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Report the errors.
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+ }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
\ No newline at end of file
diff --git a/Ch03/login/register-header.php b/Ch03/login/register-header.php
new file mode 100644
index 0000000..44f145a
--- /dev/null
+++ b/Ch03/login/register-header.php
@@ -0,0 +1,15 @@
+
+
+
+
+
Header Goes Here
+
+
diff --git a/Ch03/login/register-page.php b/Ch03/login/register-page.php
new file mode 100644
index 0000000..3d419c7
--- /dev/null
+++ b/Ch03/login/register-page.php
@@ -0,0 +1,108 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+On the Home Page, you will now be able to login and add new quotes to the message board.
+
+
+
+
+
+
+
+
+
diff --git a/Ch03/login/register-view-users.php b/Ch03/login/register-view-users.php
new file mode 100644
index 0000000..2859874
--- /dev/null
+++ b/Ch03/login/register-view-users.php
@@ -0,0 +1,93 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
';
+ }
+ echo ''; // Close the table.
+ // #7
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/header-admin.php b/Ch04/admintable/admintable/header-admin.php
new file mode 100644
index 0000000..6d014af
--- /dev/null
+++ b/Ch04/admintable/admintable/header-admin.php
@@ -0,0 +1,14 @@
+
+
+
+
+
Header Goes Here
+
+
diff --git a/Ch04/admintable/admintable/header-members.php b/Ch04/admintable/admintable/header-members.php
new file mode 100644
index 0000000..3bf6406
--- /dev/null
+++ b/Ch04/admintable/admintable/header-members.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/header-thanks.php b/Ch04/admintable/admintable/header-thanks.php
new file mode 100644
index 0000000..b0b0b07
--- /dev/null
+++ b/Ch04/admintable/admintable/header-thanks.php
@@ -0,0 +1,12 @@
+
+
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/index.php b/Ch04/admintable/admintable/index.php
new file mode 100644
index 0000000..e577826
--- /dev/null
+++ b/Ch04/admintable/admintable/index.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
+
+
diff --git a/Ch04/admintable/admintable/logo.jpg b/Ch04/admintable/admintable/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch04/admintable/admintable/logo.jpg differ
diff --git a/Ch04/admintable/admintable/logout.php b/Ch04/admintable/admintable/logout.php
new file mode 100644
index 0000000..d8abea1
--- /dev/null
+++ b/Ch04/admintable/admintable/logout.php
@@ -0,0 +1,18 @@
+
+
+
+
+Members page
+
+
+
+
+
+
+
+
+
+
+
+
+
+Welcome to the Members Page!';
+?>
+
+
+
Member's Events
+
The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+
+
+
+
Special offers to members only.
+
T-Shirts £10.00
+
+
+
+
+
>
+
+
+
+
diff --git a/Ch04/admintable/admintable/mysqli_connect.php b/Ch04/admintable/admintable/mysqli_connect.php
new file mode 100644
index 0000000..ba1b280
--- /dev/null
+++ b/Ch04/admintable/admintable/mysqli_connect.php
@@ -0,0 +1,11 @@
+
+ Home
+
+
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/password-header.php b/Ch04/admintable/admintable/password-header.php
new file mode 100644
index 0000000..e6fc6c8
--- /dev/null
+++ b/Ch04/admintable/admintable/password-header.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process-change-password.php b/Ch04/admintable/admintable/process-change-password.php
new file mode 100644
index 0000000..f40f461
--- /dev/null
+++ b/Ch04/admintable/admintable/process-change-password.php
@@ -0,0 +1,110 @@
+
+ You could not change password due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Invalid email address/password combination.
+ $errorstring = 'Error! ';
+ $errorstring .= 'The email address and/or password do not match those on file.';
+ $errorstring .= " Please try again.";
+ echo "
$errorstring
";
+} }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors.
+ //header ("location: register-page.php");
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
+
+
+
+
+
+
+
diff --git a/Ch04/admintable/admintable/process-login.php b/Ch04/admintable/admintable/process-login.php
new file mode 100644
index 0000000..e014b3f
--- /dev/null
+++ b/Ch04/admintable/admintable/process-login.php
@@ -0,0 +1,83 @@
+ The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (!empty($errors)) IF.
+mysqli_stmt_free_result($q);
+mysqli_stmt_close($q);
+}
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+} // no else to allow user to enter values
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process-register-page.php b/Ch04/admintable/admintable/process-register-page.php
new file mode 100644
index 0000000..777059b
--- /dev/null
+++ b/Ch04/admintable/admintable/process-register-page.php
@@ -0,0 +1,85 @@
+";
+ $errorstring .= "System Error You could not be registered due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ mysqli_close($dbcon); // Close the database connection.
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Report the errors.
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+ }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process_admin_view_users.php b/Ch04/admintable/admintable/process_admin_view_users.php
new file mode 100644
index 0000000..5e61925
--- /dev/null
+++ b/Ch04/admintable/admintable/process_admin_view_users.php
@@ -0,0 +1,129 @@
+ $pagerows){ //if the number of records will fill more than one page
+//Calculate the number of pages and round the result up to the nearest integer
+$pages = ceil ($records/$pagerows); //
+}else{
+$pages = 1;
+}
+}//page check finished
+//Declare which record to start with
+if ((isset($_GET['s'])) &&( is_numeric($_GET['s'])))
+{
+$start = htmlspecialchars($_GET['s'], ENT_QUOTES);
+// make sure it is not executable XSS
+}else{
+$start = 0;
+}
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users ORDER BY registration_date ASC";
+$query .=" LIMIT ?, ?";
+
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind $id to SQL Statement
+mysqli_stmt_bind_param($q, "ii", $start, $pagerows);
+
+// execute query
+
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran OK (records were returned), display the records.
+// Table header. #2
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and print all the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of else ($result)
+// Now display the total number of records/members.
+$q = "SELECT COUNT(userid) FROM users";
+$result = mysqli_query ($dbcon, $q);
+$row = mysqli_fetch_array ($result, MYSQLI_NUM);
+$members = htmlspecialchars($row[0], ENT_QUOTES);
+mysqli_close($dbcon); // Close the database connection.
+$echostring = "
Total membership: $members
";
+$echostring .= "
";
+if ($pages > 1) {//
+//What number is the current page?
+$current_page = ($start/$pagerows) + 1;
+//If the page is not the first page then create a Previous link
+if ($current_page != 1) {
+$echostring .= 'Previous ';
+}
+//Create a Next link
+if ($current_page != $pages) {
+$echostring .= ' Next ';
+}
+$echostring .= '
';
+echo $echostring;
+}
+//}
+//mysqli_close($dbcon); // Close the database connection.
+} //end of try
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process_delete_record.php b/Ch04/admintable/admintable/process_delete_record.php
new file mode 100644
index 0000000..1b31598
--- /dev/null
+++ b/Ch04/admintable/admintable/process_delete_record.php
@@ -0,0 +1,95 @@
+The record has been deleted.';
+ } else { // If the query did not run OK display public message
+ echo '
The record could not be deleted.';
+ echo ' Either it does not exist or due to a system error.
';
+ // echo '
' . mysqli_error($dbcon ) . ' Query: ' . $q . '
';
+ // Debugging message. When live comment out because this displays sql
+ }
+ } else { // User did not confirm deletion.
+ echo '
The user has NOT been deleted as you requested
';
+ }
+} else { // Show the form. #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query = "SELECT CONCAT(first_name, ' ', last_name) FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, "s", $id);
+
+ // execute query
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+$row = mysqli_fetch_array($result, MYSQLI_NUM); // get user info
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+
+ // Display the record being deleted:
+ $user = htmlspecialchars($row[0], ENT_QUOTES);
+?>
+
+ Are you sure you want to permanently delete ?
+ ';
+This page has been accessed in error.';
+ echo '
';
+ }
+} // End of the main submission conditional.
+mysqli_stmt_close($q);
+mysqli_close($dbcon );
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try again.";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again soon.";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process_edit_record.php b/Ch04/admintable/admintable/process_edit_record.php
new file mode 100644
index 0000000..70234ef
--- /dev/null
+++ b/Ch04/admintable/admintable/process_edit_record.php
@@ -0,0 +1,156 @@
+This page has been accessed in error.';
+ include ('footer.php');
+ exit();
+}
+
+require ('./mysqli_connect.php');
+// Has the form been submitted?
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $errors = array();
+ // Look for the first name:
+ $first_name = filter_var( $_POST['first_name'], FILTER_SANITIZE_STRING);
+ if (empty($first_name)) {
+ $errors[] = 'You forgot to enter your first name.';
+ }
+ // Look for the last name:
+ $last_name = filter_var( $_POST['last_name'], FILTER_SANITIZE_STRING);
+ if (empty($last_name)) {
+ $errors[] = 'You forgot to enter your last name.';
+ }
+ // Look for the email address:
+ $email = filter_var( $_POST['email'], FILTER_SANITIZE_EMAIL);
+ if ((empty($email)) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+ if (empty($errors)) { // If everything's OK. #2
+ $q = mysqli_stmt_init($dbcon);
+ $query = 'SELECT userid FROM users WHERE email=? AND userid !=?';
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'si', $email, $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+ $result = mysqli_stmt_get_result($q);
+
+ if (mysqli_num_rows($result) == 0) { // e-mail does not exist in another record
+ $query = 'UPDATE users SET first_name=?, last_name=?, email=?';
+ $query .= ' WHERE userid=? LIMIT 1';
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind values to SQL Statement
+
+ mysqli_stmt_bind_param($q, 'sssi', $first_name, $last_name, $email, $id);
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ if (mysqli_stmt_affected_rows($q) == 1) { // Update OK
+
+ // Echo a message if the edit was satisfactory:
+ echo '
The user has been edited.
';
+ } else { // Echo a message if the query failed.
+ echo '
The user could not be edited due to a system error.';
+ echo ' We apologize for any inconvenience.
'; // Public message.
+ //echo '
' . mysqli_error($dbcon) . ' Query: ' . $q . '
'; // Debugging message.
+ // Message above is only for debug and should not display sql in live mode
+ }
+ } else { // Already registered.
+ echo '
The email address has already been registered.
';
+ }
+ } else { // Display the errors.
+ echo '
The following error(s) occurred: ';
+ foreach ($errors as $msg) { // Echo each error.
+ echo " - $msg \n";
+ }
+ echo '
Please try again.
';
+ } // End of if (empty($errors))section.
+} // End of the conditionals
+// Select the user's information to display in textboxes: #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query = "SELECT first_name, last_name, email FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'i', $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+ $row = mysqli_fetch_array($result, MYSQLI_NUM);
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+ // Get the user's information:
+
+ // Create the form:
+?>
+
Edit Record
+
+This page has been accessed in error.';
+}
+mysqli_stmt_free_result($q);
+mysqli_close($dbcon);
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try later";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again later";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process_temp_view_found_record.php b/Ch04/admintable/admintable/process_temp_view_found_record.php
new file mode 100644
index 0000000..0d7bf25
--- /dev/null
+++ b/Ch04/admintable/admintable/process_temp_view_found_record.php
@@ -0,0 +1,70 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users WHERE ";
+$query .= "last_name='Smith' AND first_name='James' ";
+$query .="ORDER BY registration_date ASC ";
+// Perpared statement not needed because string is hard coded
+$result = mysqli_query ($dbcon, $query); // Run the query.
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/process_view_found_record.php b/Ch04/admintable/admintable/process_view_found_record.php
new file mode 100644
index 0000000..def6abf
--- /dev/null
+++ b/Ch04/admintable/admintable/process_view_found_record.php
@@ -0,0 +1,82 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+$first_name = htmlspecialchars($_POST['first_name'], ENT_QUOTES);
+$last_name = htmlspecialchars($_POST['last_name'], ENT_QUOTES);
+// Since it's a prepared statement below this sanitizing is not needed
+// However, to consistantly retrieve than sanitize is a good habit
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users WHERE ";
+$query .= "last_name=? AND first_name=? ";
+$query .="ORDER BY registration_date ASC ";
+// Prepared statement not needed because string is hard coded
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind values to SQL Statement
+mysqli_stmt_bind_param($q, 'ss', $last_name, $first_name);
+
+// execute query
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch04/admintable/admintable/register-header.php b/Ch04/admintable/admintable/register-header.php
new file mode 100644
index 0000000..1a24c07
--- /dev/null
+++ b/Ch04/admintable/admintable/register-header.php
@@ -0,0 +1,15 @@
+
+
+
+
+
Header Goes Here
+
+
diff --git a/Ch04/admintable/admintable/register-page.php b/Ch04/admintable/admintable/register-page.php
new file mode 100644
index 0000000..3d419c7
--- /dev/null
+++ b/Ch04/admintable/admintable/register-page.php
@@ -0,0 +1,108 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+On the Home Page, you will now be able to login and add new quotes to the message board.
+
+
+
+
+
+
+
+
+
diff --git a/Ch04/admintable/admintable/register-view-users.php b/Ch04/admintable/admintable/register-view-users.php
new file mode 100644
index 0000000..2859874
--- /dev/null
+++ b/Ch04/admintable/admintable/register-view-users.php
@@ -0,0 +1,93 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
';
+ }
+ echo ''; // Close the table.
+ // #7
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
\ No newline at end of file
diff --git a/Ch05/postal/header-admin.php b/Ch05/postal/header-admin.php
new file mode 100644
index 0000000..d9f4072
--- /dev/null
+++ b/Ch05/postal/header-admin.php
@@ -0,0 +1,15 @@
+
+
+
+
+
Header Goes Here
+
+
diff --git a/Ch05/postal/header-members.php b/Ch05/postal/header-members.php
new file mode 100644
index 0000000..3bf6406
--- /dev/null
+++ b/Ch05/postal/header-members.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch05/postal/header-thanks.php b/Ch05/postal/header-thanks.php
new file mode 100644
index 0000000..b0b0b07
--- /dev/null
+++ b/Ch05/postal/header-thanks.php
@@ -0,0 +1,12 @@
+
+
\ No newline at end of file
diff --git a/Ch05/postal/images/Thumbs.db b/Ch05/postal/images/Thumbs.db
new file mode 100644
index 0000000..36a1b2f
Binary files /dev/null and b/Ch05/postal/images/Thumbs.db differ
diff --git a/Ch05/postal/images/polo.png b/Ch05/postal/images/polo.png
new file mode 100644
index 0000000..bca2bd2
Binary files /dev/null and b/Ch05/postal/images/polo.png differ
diff --git a/Ch05/postal/images/tile-pale.jpg b/Ch05/postal/images/tile-pale.jpg
new file mode 100644
index 0000000..ae45d50
Binary files /dev/null and b/Ch05/postal/images/tile-pale.jpg differ
diff --git a/Ch05/postal/images/vertical_solution_PP.png b/Ch05/postal/images/vertical_solution_PP.png
new file mode 100644
index 0000000..8693bd4
Binary files /dev/null and b/Ch05/postal/images/vertical_solution_PP.png differ
diff --git a/Ch05/postal/index.php b/Ch05/postal/index.php
new file mode 100644
index 0000000..e577826
--- /dev/null
+++ b/Ch05/postal/index.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
+
+
diff --git a/Ch05/postal/logo.jpg b/Ch05/postal/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch05/postal/logo.jpg differ
diff --git a/Ch05/postal/logout.php b/Ch05/postal/logout.php
new file mode 100644
index 0000000..d8abea1
--- /dev/null
+++ b/Ch05/postal/logout.php
@@ -0,0 +1,18 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch05/postal/members-page.php b/Ch05/postal/members-page.php
new file mode 100644
index 0000000..e6252d1
--- /dev/null
+++ b/Ch05/postal/members-page.php
@@ -0,0 +1,61 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Member's Page
+
The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+
+
Special offers to members only.
+
T-Shirts 10.00
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch05/postal/mysqli_connect.php b/Ch05/postal/mysqli_connect.php
new file mode 100644
index 0000000..70bf5fc
--- /dev/null
+++ b/Ch05/postal/mysqli_connect.php
@@ -0,0 +1,11 @@
+
+ Home
+
+
\ No newline at end of file
diff --git a/Ch05/postal/password-header.php b/Ch05/postal/password-header.php
new file mode 100644
index 0000000..e6fc6c8
--- /dev/null
+++ b/Ch05/postal/password-header.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch05/postal/postaldb.sql b/Ch05/postal/postaldb.sql
new file mode 100644
index 0000000..89a92b5
--- /dev/null
+++ b/Ch05/postal/postaldb.sql
@@ -0,0 +1,109 @@
+-- phpMyAdmin SQL Dump
+-- version 4.7.4
+-- https://www.phpmyadmin.net/
+--
+-- Host: 127.0.0.1
+-- Generation Time: Jul 27, 2018 at 06:56 PM
+-- Server version: 10.1.28-MariaDB
+-- PHP Version: 7.1.11
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET AUTOCOMMIT = 0;
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Database: `postaldb`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `prices`
+--
+
+CREATE TABLE `prices` (
+ `oneyeargb` decimal(6,0) NOT NULL,
+ `oneyearus` decimal(6,0) NOT NULL,
+ `fiveyeargb` decimal(6,0) NOT NULL,
+ `fiveyearus` decimal(6,0) NOT NULL,
+ `militarygb` decimal(6,0) NOT NULL,
+ `militaryus` decimal(6,0) NOT NULL,
+ `u21gb` decimal(6,0) NOT NULL,
+ `u21us` decimal(6,0) NOT NULL,
+ `minpricegb` decimal(6,0) NOT NULL,
+ `minpriceus` decimal(6,0) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
+--
+-- Dumping data for table `prices`
+--
+
+INSERT INTO `prices` (`oneyeargb`, `oneyearus`, `fiveyeargb`, `fiveyearus`, `militarygb`, `militaryus`, `u21gb`, `u21us`, `minpricegb`, `minpriceus`) VALUES
+('30', '40', '125', '140', '5', '8', '2', '3', '15', '20');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `users`
+--
+
+CREATE TABLE `users` (
+ `userid` mediumint(6) UNSIGNED NOT NULL,
+ `first_name` varchar(30) COLLATE utf8_bin NOT NULL,
+ `last_name` varchar(40) COLLATE utf8_bin NOT NULL,
+ `email` varchar(50) COLLATE utf8_bin NOT NULL,
+ `password` char(60) COLLATE utf8_bin NOT NULL,
+ `registration_date` datetime NOT NULL,
+ `user_level` tinyint(1) NOT NULL,
+ `address1` varchar(50) COLLATE utf8_bin NOT NULL,
+ `address2` varchar(50) COLLATE utf8_bin DEFAULT NULL,
+ `city` varchar(50) COLLATE utf8_bin NOT NULL,
+ `state_country` char(25) COLLATE utf8_bin NOT NULL,
+ `zcode_pcode` char(10) COLLATE utf8_bin NOT NULL,
+ `phone` char(15) COLLATE utf8_bin DEFAULT NULL,
+ `paid` enum('No','Yes') COLLATE utf8_bin NOT NULL,
+ `class` char(20) COLLATE utf8_bin NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
+--
+-- Dumping data for table `users`
+--
+
+INSERT INTO `users` (`userid`, `first_name`, `last_name`, `email`, `password`, `registration_date`, `user_level`, `address1`, `address2`, `city`, `state_country`, `zcode_pcode`, `phone`, `paid`, `class`) VALUES
+(1, 'James', 'Smith', 'jsmith@myisp.com', '$2y$10$9A7tLasMBRhpgHGXvAR3o.7o9TTl8MCI90FjVqe2NxtreSqMwU5Ze', '2017-12-08 18:13:48', 1, '2 The Street', NULL, 'Townsville', 'CA', '33040', '3055551111', 'No', '125'),
+(2, 'Jack', 'Smith', 'jsmith@outcook.com', '$2y$10$7bRW0hJkQFQs6QKxLYm4Cud/Mq0/opjEGLdLPECCWoi9EScVLNg32', '2017-12-08 18:18:35', 0, '2 The Street', NULL, 'Townsville', 'CA', '33040', '3055551111', 'No', '30'),
+(3, 'Mike', 'Rosoft', 'miker@myisp.com', '$2y$10$2ozl5Ds/F.IdEDGnfAovku5DxQubPbzxfeFKCpZDsi74wLEmeCeSy', '2017-12-08 18:19:43', 0, '2 The Street', NULL, 'Townsville', 'CA', '33040', '3055551111', 'No', '2'),
+(4, 'Olive', 'Branch', 'obranch@myisp.co.uk', '$2y$10$IiCEJot1JJ3X2WUjAx9e4ecQL2eUbBsCbUqNwljgxrX7cLtKebpAe', '2017-12-08 18:21:08', 0, '2 The Street', 'The Village', 'Townsville', 'CA', '33040', '3055551111', 'No', '2'),
+(5, 'Frank', 'Incense', 'incense@myisp.net', '$2y$10$Tm6mFieRmBMAXPS4VqE.aubkadLmW2clnrDkTS3ZKbyXFvlNBkZzu', '2017-12-08 18:22:53', 0, '2 The Street', 'The Village', 'Townsville', 'CA', '33040', NULL, 'No', '15');
+
+--
+-- Indexes for dumped tables
+--
+
+--
+-- Indexes for table `users`
+--
+ALTER TABLE `users`
+ ADD PRIMARY KEY (`userid`);
+
+--
+-- AUTO_INCREMENT for dumped tables
+--
+
+--
+-- AUTO_INCREMENT for table `users`
+--
+ALTER TABLE `users`
+ MODIFY `userid` mediumint(6) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/Ch05/postal/process-change-password.php b/Ch05/postal/process-change-password.php
new file mode 100644
index 0000000..f40f461
--- /dev/null
+++ b/Ch05/postal/process-change-password.php
@@ -0,0 +1,110 @@
+
+ You could not change password due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Invalid email address/password combination.
+ $errorstring = 'Error! ';
+ $errorstring .= 'The email address and/or password do not match those on file.';
+ $errorstring .= " Please try again.";
+ echo "
$errorstring
";
+} }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors.
+ //header ("location: register-page.php");
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
+
+
+
+
+
+
+
diff --git a/Ch05/postal/process-login.php b/Ch05/postal/process-login.php
new file mode 100644
index 0000000..139ac70
--- /dev/null
+++ b/Ch05/postal/process-login.php
@@ -0,0 +1,86 @@
+ The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (!empty($errors)) IF.
+mysqli_stmt_free_result($q);
+mysqli_stmt_close($q);
+}
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+} // no else to allow user to enter values
+?>
\ No newline at end of file
diff --git a/Ch05/postal/process-register-page.php b/Ch05/postal/process-register-page.php
new file mode 100644
index 0000000..93916e2
--- /dev/null
+++ b/Ch05/postal/process-register-page.php
@@ -0,0 +1,144 @@
+";
+ $errorstring .= "System Error You could not be registered due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ mysqli_close($dbcon); // Close the database connection.
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ }else{//The email address is already registered #4
+ $errorstring = 'The email address is already registered.';
+ echo "
$errorstring
";
+ }
+ } else { // Report the errors.
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+ }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
\ No newline at end of file
diff --git a/Ch05/postal/process_admin_view_users.php b/Ch05/postal/process_admin_view_users.php
new file mode 100644
index 0000000..5e61925
--- /dev/null
+++ b/Ch05/postal/process_admin_view_users.php
@@ -0,0 +1,129 @@
+ $pagerows){ //if the number of records will fill more than one page
+//Calculate the number of pages and round the result up to the nearest integer
+$pages = ceil ($records/$pagerows); //
+}else{
+$pages = 1;
+}
+}//page check finished
+//Declare which record to start with
+if ((isset($_GET['s'])) &&( is_numeric($_GET['s'])))
+{
+$start = htmlspecialchars($_GET['s'], ENT_QUOTES);
+// make sure it is not executable XSS
+}else{
+$start = 0;
+}
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users ORDER BY registration_date ASC";
+$query .=" LIMIT ?, ?";
+
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind $id to SQL Statement
+mysqli_stmt_bind_param($q, "ii", $start, $pagerows);
+
+// execute query
+
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran OK (records were returned), display the records.
+// Table header. #2
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and print all the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of else ($result)
+// Now display the total number of records/members.
+$q = "SELECT COUNT(userid) FROM users";
+$result = mysqli_query ($dbcon, $q);
+$row = mysqli_fetch_array ($result, MYSQLI_NUM);
+$members = htmlspecialchars($row[0], ENT_QUOTES);
+mysqli_close($dbcon); // Close the database connection.
+$echostring = "
Total membership: $members
";
+$echostring .= "
";
+if ($pages > 1) {//
+//What number is the current page?
+$current_page = ($start/$pagerows) + 1;
+//If the page is not the first page then create a Previous link
+if ($current_page != 1) {
+$echostring .= 'Previous ';
+}
+//Create a Next link
+if ($current_page != $pages) {
+$echostring .= ' Next ';
+}
+$echostring .= '
';
+echo $echostring;
+}
+//}
+//mysqli_close($dbcon); // Close the database connection.
+} //end of try
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
\ No newline at end of file
diff --git a/Ch05/postal/process_delete_record.php b/Ch05/postal/process_delete_record.php
new file mode 100644
index 0000000..1b31598
--- /dev/null
+++ b/Ch05/postal/process_delete_record.php
@@ -0,0 +1,95 @@
+The record has been deleted.';
+ } else { // If the query did not run OK display public message
+ echo '
The record could not be deleted.';
+ echo ' Either it does not exist or due to a system error.
';
+ // echo '
' . mysqli_error($dbcon ) . ' Query: ' . $q . '
';
+ // Debugging message. When live comment out because this displays sql
+ }
+ } else { // User did not confirm deletion.
+ echo '
The user has NOT been deleted as you requested
';
+ }
+} else { // Show the form. #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query = "SELECT CONCAT(first_name, ' ', last_name) FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, "s", $id);
+
+ // execute query
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+$row = mysqli_fetch_array($result, MYSQLI_NUM); // get user info
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+
+ // Display the record being deleted:
+ $user = htmlspecialchars($row[0], ENT_QUOTES);
+?>
+
+ Are you sure you want to permanently delete ?
+ ';
+This page has been accessed in error.';
+ echo '
';
+ }
+} // End of the main submission conditional.
+mysqli_stmt_close($q);
+mysqli_close($dbcon );
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try again.";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again soon.";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch05/postal/process_edit_record.php b/Ch05/postal/process_edit_record.php
new file mode 100644
index 0000000..8d5899f
--- /dev/null
+++ b/Ch05/postal/process_edit_record.php
@@ -0,0 +1,187 @@
+This page has been accessed in error.';
+ include ('footer.php');
+ exit();
+}
+
+require ('./mysqli_connect.php');
+// Has the form been submitted?
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $errors = array();
+ // Look for the first name:
+ $first_name = filter_var( $_POST['first_name'], FILTER_SANITIZE_STRING);
+ if (empty($first_name)) {
+ $errors[] = 'You forgot to enter your first name.';
+ }
+ // Look for the last name:
+ $last_name = filter_var( $_POST['last_name'], FILTER_SANITIZE_STRING);
+ if (empty($last_name)) {
+ $errors[] = 'You forgot to enter your last name.';
+ }
+ // Look for the email address:
+ $email = filter_var( $_POST['email'], FILTER_SANITIZE_EMAIL);
+ if ((empty($email)) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+ // Look for class:
+ $class = filter_var( $_POST['class'], FILTER_SANITIZE_NUMBER_INT);
+ if (empty($class)) {
+ $errors[] = 'You forgot to the class or it is not numeric.';
+ }
+ // Look for the Paid Status:
+ $paid = filter_var( $_POST['paid'], FILTER_SANITIZE_STRING);
+ if (empty($paid)) {
+ $errors[] = 'You forgot to enter the paid status.';
+ }
+ if (!($paid == "No") || ($paid == "Yes")) {
+ $errors[] = "Paid must be No or Yes.";
+ }
+ if (empty($errors)) { // If everything's OK.
+ $q = mysqli_stmt_init($dbcon);
+ $query = 'SELECT userid FROM users WHERE email=? AND userid !=?';
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'si', $email, $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+ $result = mysqli_stmt_get_result($q);
+
+ if (mysqli_num_rows($result) == 0) { // e-mail does not exist in another record
+ $query = 'UPDATE users SET first_name=?, last_name=?, email=?,';
+ $query .= ' class=?, paid=?';
+ $query .= ' WHERE userid=? LIMIT 1';
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind values to SQL Statement
+
+ mysqli_stmt_bind_param($q, 'sssssi', $first_name, $last_name, $email, $class, $paid, $id);
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ if (mysqli_stmt_affected_rows($q) == 1) { // Update OK
+
+ // Echo a message if the edit was satisfactory:
+ echo '
The user has been edited.
';
+ } else { // Echo a message if the query failed.
+ echo '
The user could not be edited due to a system error.';
+ echo ' We apologize for any inconvenience.
'; // Public message.
+ //echo '
' . mysqli_error($dbcon) . ' Query: ' . $q . '
'; // Debugging message.
+ // Message above is only for debug and should not display sql in live mode
+ }
+ } else { // Already registered.
+ echo '
The email address has already been registered.
';
+ }
+ } else { // Display the errors.
+ echo '
The following error(s) occurred: ';
+ foreach ($errors as $msg) { // Echo each error.
+ echo " - $msg \n";
+ }
+ echo '
Please try again.
';
+ } // End of if (empty($errors))section.
+} // End of the conditionals
+// Select the user's information to display in textboxes: #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query =
+ "SELECT first_name, last_name, email, class, paid FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'i', $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+ $row = mysqli_fetch_array($result, MYSQLI_NUM);
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+ // Get the user's information:
+
+ // Create the form:
+?>
+
Edit a Record
+
+This page has been accessed in error.';
+}
+mysqli_stmt_free_result($q);
+mysqli_close($dbcon);
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try later";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again later";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch05/postal/process_temp_view_found_record.php b/Ch05/postal/process_temp_view_found_record.php
new file mode 100644
index 0000000..0d7bf25
--- /dev/null
+++ b/Ch05/postal/process_temp_view_found_record.php
@@ -0,0 +1,70 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users WHERE ";
+$query .= "last_name='Smith' AND first_name='James' ";
+$query .="ORDER BY registration_date ASC ";
+// Perpared statement not needed because string is hard coded
+$result = mysqli_query ($dbcon, $query); // Run the query.
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch05/postal/process_view_found_record.php b/Ch05/postal/process_view_found_record.php
new file mode 100644
index 0000000..8bd6b5c
--- /dev/null
+++ b/Ch05/postal/process_view_found_record.php
@@ -0,0 +1,89 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+$first_name = htmlspecialchars($_POST['first_name'], ENT_QUOTES);
+$last_name = htmlspecialchars($_POST['last_name'], ENT_QUOTES);
+// Since it's a prepared statement below this sanitizing is not needed
+// However, to consistantly retrieve than sanitize is a good habit
+
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, class, paid, userid FROM users WHERE ";
+$query .= "last_name=? AND first_name=? ";
+$query .="ORDER BY registration_date ASC ";
+
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind values to SQL Statement
+mysqli_stmt_bind_param($q, 'ss', $last_name, $first_name);
+
+// execute query
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
Class
+
Paid
+
';
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ $class = htmlspecialchars($row['class'], ENT_QUOTES);
+ $paid = htmlspecialchars($row['paid'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch05/postal/register-header.php b/Ch05/postal/register-header.php
new file mode 100644
index 0000000..1a24c07
--- /dev/null
+++ b/Ch05/postal/register-header.php
@@ -0,0 +1,15 @@
+
+
+
+getMessage();
+ print "The system is busy please try later";
+ }
+catch(Error $e)
+{
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+}
+?>
+
+
diff --git a/Ch05/postal/register-view-users.php b/Ch05/postal/register-view-users.php
new file mode 100644
index 0000000..2859874
--- /dev/null
+++ b/Ch05/postal/register-view-users.php
@@ -0,0 +1,93 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
';
+ }
+ echo ''; // Close the table.
+ // #7
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/header-admin.php b/Ch06/finalpostal/includes/header-admin.php
new file mode 100644
index 0000000..50c305b
--- /dev/null
+++ b/Ch06/finalpostal/includes/header-admin.php
@@ -0,0 +1,15 @@
+
+
+
+
+
Header Goes Here
+
+
diff --git a/Ch06/finalpostal/includes/header-members.php b/Ch06/finalpostal/includes/header-members.php
new file mode 100644
index 0000000..3bf6406
--- /dev/null
+++ b/Ch06/finalpostal/includes/header-members.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/header-thanks.php b/Ch06/finalpostal/includes/header-thanks.php
new file mode 100644
index 0000000..b0b0b07
--- /dev/null
+++ b/Ch06/finalpostal/includes/header-thanks.php
@@ -0,0 +1,12 @@
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/info-col-cards.php b/Ch06/finalpostal/includes/info-col-cards.php
new file mode 100644
index 0000000..fda610e
--- /dev/null
+++ b/Ch06/finalpostal/includes/info-col-cards.php
@@ -0,0 +1,4 @@
+
+
+
diff --git a/Ch06/finalpostal/includes/login-header.php b/Ch06/finalpostal/includes/login-header.php
new file mode 100644
index 0000000..9602ddc
--- /dev/null
+++ b/Ch06/finalpostal/includes/login-header.php
@@ -0,0 +1,13 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/logo.jpg b/Ch06/finalpostal/includes/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch06/finalpostal/includes/logo.jpg differ
diff --git a/Ch06/finalpostal/includes/members-header.php b/Ch06/finalpostal/includes/members-header.php
new file mode 100644
index 0000000..de443b4
--- /dev/null
+++ b/Ch06/finalpostal/includes/members-header.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/nav.php b/Ch06/finalpostal/includes/nav.php
new file mode 100644
index 0000000..db873ad
--- /dev/null
+++ b/Ch06/finalpostal/includes/nav.php
@@ -0,0 +1,15 @@
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/password-header.php b/Ch06/finalpostal/includes/password-header.php
new file mode 100644
index 0000000..e6fc6c8
--- /dev/null
+++ b/Ch06/finalpostal/includes/password-header.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/includes/register-header.php b/Ch06/finalpostal/includes/register-header.php
new file mode 100644
index 0000000..b1a43e8
--- /dev/null
+++ b/Ch06/finalpostal/includes/register-header.php
@@ -0,0 +1,15 @@
+
+
+
+getMessage();
+ print "The system is busy please try later";
+ }
+catch(Error $e)
+{
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+}
+?>
+
+
diff --git a/Ch06/finalpostal/includes/thanks-header.php b/Ch06/finalpostal/includes/thanks-header.php
new file mode 100644
index 0000000..7a0b906
--- /dev/null
+++ b/Ch06/finalpostal/includes/thanks-header.php
@@ -0,0 +1,11 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch06/finalpostal/index.php b/Ch06/finalpostal/index.php
new file mode 100644
index 0000000..7e9feef
--- /dev/null
+++ b/Ch06/finalpostal/index.php
@@ -0,0 +1,48 @@
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Home Page
+
The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content. The home page content. The home page content.
+ The home page content. The home page content.
+ The home page content. The home page content. The home page content.
+
+
diff --git a/Ch06/finalpostal/logo.jpg b/Ch06/finalpostal/logo.jpg
new file mode 100644
index 0000000..4fe01c8
Binary files /dev/null and b/Ch06/finalpostal/logo.jpg differ
diff --git a/Ch06/finalpostal/logout.php b/Ch06/finalpostal/logout.php
new file mode 100644
index 0000000..d8abea1
--- /dev/null
+++ b/Ch06/finalpostal/logout.php
@@ -0,0 +1,18 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is the Member's Page
+
The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+ The members page content. The members page content. The members page content.
+
+On the Home Page, you will now be able to login with your new password.
+
+
+
+
+
+
+
+
+
diff --git a/Ch06/finalpostal/process-change-password.php b/Ch06/finalpostal/process-change-password.php
new file mode 100644
index 0000000..13447ae
--- /dev/null
+++ b/Ch06/finalpostal/process-change-password.php
@@ -0,0 +1,126 @@
+
+ 60))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+// Check for a password and match against the confirmed password:
+$password = filter_var( $_POST['password'], FILTER_SANITIZE_STRING);
+$string_length = strlen($password);
+if (empty($password)){ //
+$errors[] ='Please enter a valid old password';
+}
+else {
+if(!preg_match( '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,12}$/',
+$password)) { //
+$errors[] = 'Invalid password, 8 to 12 chars, one upper, one lower, one number, one special.';
+} else
+{
+ // Prepare and check new password
+ $new_password = filter_var( $_POST['password1'], FILTER_SANITIZE_STRING);
+ $verify_password = filter_var( $_POST['password2'], FILTER_SANITIZE_STRING);
+ if (!empty($new_password)) {
+ if(preg_match( '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,12}$/',
+$new_password)) {
+ if (($new_password != $verify_password) ||
+ ( $password == $new_password ))
+ {
+ $errors[] = 'Your new password did not match the confirmed password and/or ';
+ $errors[] = 'Your old password is the same as your new password.';
+ }
+} else {
+ $errors[] = 'Your new password is not in correct format.';
+}
+ } else {
+ $errors[] = 'You did not enter a new password.';
+ }
+}
+}
+ if (empty($errors)) { // If everything's OK.
+try {
+ // Check that the user has entered the right email address/password combination:
+ $query = "SELECT userid, password FROM users WHERE ( email=? )";
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+ // use prepared statement to insure that only text is inserted
+ // bind fields to SQL Statement
+ mysqli_stmt_bind_param($q, 's', $email);
+ // execute query
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+ $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
+ if ((mysqli_num_rows($result) == 1)
+ && (password_verify($password, $row['password'])))
+ { // Found one record
+ // Change the password in the database...
+ // Hash password current 60 characters but can increase
+ $hashed_passcode = password_hash($new_password, PASSWORD_DEFAULT);
+ // Make the query:
+ $query = "UPDATE users SET password=? WHERE email=?";
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+ // use prepared statement to insure that only text is inserted
+ // bind fields to SQL Statement
+ mysqli_stmt_bind_param($q, 'ss', $hashed_passcode, $email);
+ // execute query
+ mysqli_stmt_execute($q);
+ if (mysqli_stmt_affected_rows($q) == 1) { // one row updated
+ // Echo a message
+ header ("location: password-thanks.php");
+ exit();
+ } else { // If it did not run OK.
+ // Public message:
+ $errorstring = "System Error! You could not change password due ";
+ $errorstring .= "to a system error. We apologize for any inconvenience.";
+ echo "
$errorstring
";
+ // Debugging message below do not use in production
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $query . '
';
+ // include footer then close program to stop execution
+ echo '';
+ exit();
+ }
+ } else { // Invalid email address/password combination.
+ $errorstring = 'Error! ';
+ $errorstring .= 'The email address and/or password do not match those on file.';
+ $errorstring .= " Please try again.";
+ echo "
$errorstring
";
+} }
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+ } else { // Report the errors.
+ //header ("location: register-page.php");
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+?>
+
+
+
+
+
+
+
diff --git a/Ch06/finalpostal/process-login.php b/Ch06/finalpostal/process-login.php
new file mode 100644
index 0000000..180dedc
--- /dev/null
+++ b/Ch06/finalpostal/process-login.php
@@ -0,0 +1,93 @@
+ 60))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+// Check for a password and match against the confirmed password:
+$password = filter_var( $_POST['password'], FILTER_SANITIZE_STRING);
+$string_length = strlen($password);
+if (empty($password)){
+$errors[] ='Please enter a valid password';
+}
+else {
+if(!preg_match( '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,12}$/',
+$password)) { // #8
+$errors[] = 'Invalid password, 8 to 12 chars, one upper, one lower, one number, one special.';
+}
+}
+ if (empty($errors)) { // If everything's OK. #1
+// Retrieve the user_id, psword, first_name and user_level for that
+// email/password combination
+ $query = "SELECT userid, password, first_name, user_level FROM users ";
+ $query .= "WHERE paid='Yes' AND email=?";
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, "s", $email);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+$row = mysqli_fetch_array($result, MYSQLI_NUM);
+if (mysqli_num_rows($result) == 1) {
+//if one database row (record) matches the input:-
+// Start the session, fetch the record and insert the
+// values in an array
+if (password_verify($password, $row[1])) { //#2
+session_start();
+// Ensure that the user level is an integer.
+$_SESSION['user_level'] = (int) $row[3];
+// Use a ternary operation to set the URL #3
+$url = ($_SESSION['user_level'] === 1) ? 'admin-page.php' :
+ 'members-page.php';
+header('Location: ' . $url);
+// Make the browser load either the members or the admin page
+} else { // No password match was made.
+$errors[] = 'E-mail/Password entered does not match our records. ';
+$errors[] = 'Perhaps your fee has not yet been processed from ';
+$errors[] = ' PayPal or the credit card.';
+$errors[] = 'Perhaps you need to register, just click the Register ';
+$errors[] = 'button on the header menu';
+}
+} else { // No e-mail match was made.
+$errors[] = 'E-mail/Password entered does not match our records. ';
+$errors[] = 'Perhaps you need to register, just click the Register ';
+$errors[] = 'button on the header menu';
+}
+}
+if (!empty($errors)) {
+ $errorstring = "Error! The following error(s) occurred: ";
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " $msg \n";
+ }
+ $errorstring .= "Please try again. ";
+ echo "
$errorstring
";
+ }// End of if (!empty($errors)) IF.
+mysqli_stmt_free_result($q);
+mysqli_stmt_close($q);
+}
+ catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+} // no else to allow user to enter values
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process-register-page.php b/Ch06/finalpostal/process-register-page.php
new file mode 100644
index 0000000..f3a6c15
--- /dev/null
+++ b/Ch06/finalpostal/process-register-page.php
@@ -0,0 +1,195 @@
+ 60))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+// Check for a password and match against the confirmed password:
+$password1trim = filter_var( $_POST['password1'], FILTER_SANITIZE_STRING);
+$string_length = strlen($password1trim);
+if (empty($password1trim)){ // #7
+$errors[] ='Please enter a valid password';
+}
+else {
+if(!preg_match( '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,12}$/',
+$password1trim)) { // #8
+$errors[] = 'Invalid password, 8 to 12 chars, one upper, one lower, one number, one special.';
+} else
+{
+$password2trim = filter_var( $_POST['password2'], FILTER_SANITIZE_STRING);
+if($password1trim === $password2trim) { // #9
+$password = $password1trim;
+}else{
+$errors[] = 'Your two password do not match.';
+$errors[] = 'Please try again';
+}
+}
+}
+//Is the 1st address present? If it is, sanitize it
+$address1 = filter_var( $_POST['address1'], FILTER_SANITIZE_STRING);
+if ((!empty($address1)) && (preg_match('/[a-z0-9\.\s\,\-]/i', $address1)) &&
+ (strlen($address1) <= 30)) {
+ //Sanitize the trimmed 1st address
+ $address1trim = $address1;
+ }else{
+ $errors[] = 'Missing address. Only numeric, alphabetic, period, comma, dash and space. Max 30.';
+ }
+//If the 2nd address is present? If it is, sanitize it #10
+$address2 = filter_var( $_POST['address2'], FILTER_SANITIZE_STRING);
+if ((!empty($address2)) && (preg_match('/[a-z0-9\.\s\,\-]/i', $address2)) &&
+ (strlen($address2) <= 30)) {
+ //Sanitize the trimmed 2nd address
+ $address2trim = $address2;
+ }else{
+ $address2trim = NULL;
+ }
+//Is the city present? If it is, sanitize it
+$city = filter_var( $_POST['city'], FILTER_SANITIZE_STRING);
+if ((!empty($city)) && (preg_match('/[a-z\.\s]/i', $city)) &&
+ (strlen($city) <= 30)) {
+ //Sanitize the trimmed city
+ $citytrim = $city;
+ }else{
+ $errors[] = 'Missing city. Only alphabetic, period and space. Max 30.';
+ }
+//Is the state or country present? If it is, sanitize it
+$state_country = filter_var( $_POST['state_country'], FILTER_SANITIZE_STRING);
+if ((!empty($state_country)) && (preg_match('/[a-z\.\s]/i', $state_country)) &&
+ (strlen($state_country) <= 30)) {
+ //Sanitize the trimmed state or country
+ $state_countrytrim = $state_country;
+ }else{
+ $errors[] = 'Missing state/country. Only alphabetic, period and space. Max 30.';
+ }
+//Is the zip code or post code present? If it is, sanitize it
+$zcode_pcode = filter_var( $_POST['zcode_pcode'], FILTER_SANITIZE_STRING);
+$string_length = strlen($zcode_pcode);
+if ((!empty($zcode_pcode)) && (preg_match('/[a-z0-9\s]/i', $zcode_pcode)) &&
+ ($string_length <= 30) && ($string_length >= 5)) {
+ //Sanitize the trimmed zcode_pcode
+ $zcode_pcodetrim = $zcode_pcode;
+ }else{
+ $errors[] = 'Missing zip code or post code. Alphabetic, numeric, space only max 30 characters';
+ }
+//Is the secret present? If it is, sanitize it
+$secret = filter_var( $_POST['secret'], FILTER_SANITIZE_STRING);
+if ((!empty($secret)) && (preg_match('/[a-z\.\s\,\-]/i', $secret)) &&
+ (strlen($secret) <= 30)) {
+ //Sanitize the trimmed city
+ $secrettrim = $secret;
+ }else{
+ $errors[] = 'Missing city. Only alphabetic, period, comma, dash and space. Max 30.';
+ }
+//Is the phone number present? If it is, sanitize it
+$phone = filter_var( $_POST['phone'], FILTER_SANITIZE_STRING);
+if ((!empty($phone)) && (strlen($phone) <= 30)) {
+ //Sanitize the trimmed phone number
+ $phonetrim = (filter_var($phone, FILTER_SANITIZE_NUMBER_INT));
+ $phonetrim = preg_replace('/[^0-9]/', '', $phonetrim);
+ }else{
+ $phonetrim = NULL;
+ }
+//Is the class present? If it is, sanitize it
+$class = filter_var( $_POST['level'], FILTER_SANITIZE_STRING);
+if ((!empty($class)) && (strlen($class) <= 3)) {
+ //Sanitize the trimmed phone number
+ $classtrim = (filter_var($class, FILTER_SANITIZE_NUMBER_INT));
+ }else{
+ $errors[] = 'Missing Level Selection.';
+ }
+if (empty($errors)) { // If everything's OK.
+// If no problems encountered, register user in the database
+//Determine whether the email address has already been registered
+$query = "SELECT userid FROM users WHERE email = ? ";
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+mysqli_stmt_bind_param($q,'s', $emailtrim);
+mysqli_stmt_execute($q);
+$result = mysqli_stmt_get_result($q);
+
+if (mysqli_num_rows($result) == 0){//The email address has not been registered
+//already therefore register the user in the users table
+ //-------------Valid Entries - Save to database -----
+ //Start of the SUCCESSFUL SECTION. i.e all the required fields were filled out
+ $hashed_password = password_hash($password, PASSWORD_DEFAULT);
+ // Register the user in the database...
+
+ $query = "INSERT INTO users (userid, title, first_name, last_name, email, password, class, ";
+ $query .= "address1, address2, city, state_country, zcode_pcode, phone, secret, registration_date) ";
+ $query .= "VALUES ";
+ $query .= "(' ',?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+// use prepared statement to insure that only text is inserted
+// bind fields to SQL Statement
+mysqli_stmt_bind_param($q, 'sssssssssssss',
+ $titletrim, $first_nametrim, $last_nametrim, $emailtrim, $hashed_password, $classtrim, $address1trim,
+ $address2trim, $citytrim, $state_countrytrim, $zcode_pcodetrim, $phonetrim, $secrettrim);
+// execute query
+mysqli_stmt_execute($q);
+if (mysqli_stmt_affected_rows($q) == 1) {
+ header ("location: register-thanks.php?class=" . $classtrim);
+ } else {
+ // echo 'Invalid query:' . $dbcon->error;
+ $errorstring = "System is busy, please try later";
+ echo "
$errorstring
";
+ }
+ }else{//The email address is already registered
+ $errorstring = 'The email address is already registered.';
+ echo "
$errorstring
";
+}
+ } else {//End of SUCCESSFUL SECTION
+// ---------------Process User Errors---------------
+// Display the users entry errors
+$errorstring = 'Error! The following error(s) occurred: ';
+foreach ($errors as $msg) { // Print each error.
+$errorstring .= " - $msg \n";
+ }
+$errorstring .= 'Please try again.';
+echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+}
+catch(Exception $e)
+{
+ print "The system is busy, please try later";
+ //print "An Exception occurred. Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is busy, please come back later";
+ //print "An Error occurred. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_admin_view_users.php b/Ch06/finalpostal/process_admin_view_users.php
new file mode 100644
index 0000000..5e61925
--- /dev/null
+++ b/Ch06/finalpostal/process_admin_view_users.php
@@ -0,0 +1,129 @@
+ $pagerows){ //if the number of records will fill more than one page
+//Calculate the number of pages and round the result up to the nearest integer
+$pages = ceil ($records/$pagerows); //
+}else{
+$pages = 1;
+}
+}//page check finished
+//Declare which record to start with
+if ((isset($_GET['s'])) &&( is_numeric($_GET['s'])))
+{
+$start = htmlspecialchars($_GET['s'], ENT_QUOTES);
+// make sure it is not executable XSS
+}else{
+$start = 0;
+}
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users ORDER BY registration_date ASC";
+$query .=" LIMIT ?, ?";
+
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind $id to SQL Statement
+mysqli_stmt_bind_param($q, "ii", $start, $pagerows);
+
+// execute query
+
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran OK (records were returned), display the records.
+// Table header. #2
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and print all the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of else ($result)
+// Now display the total number of records/members.
+$q = "SELECT COUNT(userid) FROM users";
+$result = mysqli_query ($dbcon, $q);
+$row = mysqli_fetch_array ($result, MYSQLI_NUM);
+$members = htmlspecialchars($row[0], ENT_QUOTES);
+mysqli_close($dbcon); // Close the database connection.
+$echostring = "
Total membership: $members
";
+$echostring .= "
";
+if ($pages > 1) {//
+//What number is the current page?
+$current_page = ($start/$pagerows) + 1;
+//If the page is not the first page then create a Previous link
+if ($current_page != 1) {
+$echostring .= 'Previous ';
+}
+//Create a Next link
+if ($current_page != $pages) {
+$echostring .= ' Next ';
+}
+$echostring .= '
';
+echo $echostring;
+}
+//}
+//mysqli_close($dbcon); // Close the database connection.
+} //end of try
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_delete_record.php b/Ch06/finalpostal/process_delete_record.php
new file mode 100644
index 0000000..ab86e19
--- /dev/null
+++ b/Ch06/finalpostal/process_delete_record.php
@@ -0,0 +1,95 @@
+The record has been deleted.';
+ } else { // If the query did not run OK display public message
+ echo '
The record could not be deleted.';
+ echo ' Either it does not exist or due to a system error.
';
+ // echo '
' . mysqli_error($dbcon ) . ' Query: ' . $q . '
';
+ // Debugging message. When live comment out because this displays sql
+ }
+ } else { // User did not confirm deletion.
+ echo '
The user has NOT been deleted as you requested
';
+ }
+} else { // Show the form. #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query = "SELECT CONCAT(first_name, ' ', last_name) FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, "s", $id);
+
+ // execute query
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+$row = mysqli_fetch_array($result, MYSQLI_NUM); // get user info
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+
+ // Display the record being deleted:
+ $user = htmlspecialchars($row[0], ENT_QUOTES);
+?>
+
+ Are you sure you want to permanently delete ?
+
+This page has been accessed in error.';
+ echo '
';
+ }
+} // End of the main submission conditional.
+mysqli_stmt_close($q);
+mysqli_close($dbcon );
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try again.";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again soon.";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_edit_address.php b/Ch06/finalpostal/process_edit_address.php
new file mode 100644
index 0000000..63dc607
--- /dev/null
+++ b/Ch06/finalpostal/process_edit_address.php
@@ -0,0 +1,300 @@
+This page has been accessed in error.';
+ include ('footer.php');
+ exit();
+}
+require ('mysqli_connect.php');
+// Has the form been submitted?
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $errors = array();
+ // Look for the first name:
+//Is the title present? If it is, sanitize it
+ $title = filter_var( $_POST['title'], FILTER_SANITIZE_STRING);
+ if ((!empty($title)) && (preg_match('/[a-z\.\s]/i',$title)) &&
+ (strlen($title) <= 12)) {
+ //Sanitize the trimmed title
+ $titletrim = $title;
+ }else{
+ $titletrim = NULL; // Title is optional
+ }
+// Trim the first name
+ $first_name = filter_var( $_POST['first_name'], FILTER_SANITIZE_STRING);
+if ((!empty($first_name)) && (preg_match('/[a-z\s]/i',$first_name)) &&
+ (strlen($first_name) <= 30)) {
+ //Sanitize the trimmed first name
+ $first_nametrim = $first_name;
+ }else{
+ $errors[] = 'First name missing or not alphabetic and space characters. Max 30';
+ }
+ //Is the last name present? If it is, sanitize it
+ $last_name = filter_var( $_POST['last_name'], FILTER_SANITIZE_STRING);
+if ((!empty($last_name)) && (preg_match('/[a-z\-\s\']/i',$last_name)) &&
+ (strlen($last_name) <= 40)) {
+ //Sanitize the trimmed last name
+ $last_nametrim = $last_name;
+ }else{
+ $errors[] = 'Last name missing or not alphabetic, dash, quote or space. Max 30.';
+ }
+ //Is the 1st address present? If it is, sanitize it
+$address1 = filter_var( $_POST['address1'], FILTER_SANITIZE_STRING);
+if ((!empty($address1)) && (preg_match('/[a-z0-9\.\s\,\-]/i', $address1)) &&
+ (strlen($address1) <= 30)) {
+ //Sanitize the trimmed 1st address
+ $address1trim = $address1;
+ }else{
+ $errors[] = 'Missing address. Only numeric, alphabetic, period, comma, dash and space. Max 30.';
+ }
+//If the 2nd address is present? If it is, sanitize it #10
+$address2 = filter_var( $_POST['address2'], FILTER_SANITIZE_STRING);
+if ((!empty($address2)) && (preg_match('/[a-z0-9\.\s\,\-]/i', $address2)) &&
+ (strlen($address2) <= 30)) {
+ //Sanitize the trimmed 2nd address
+ $address2trim = $address2;
+ }else{
+ $address2trim = NULL;
+ }
+//Is the city present? If it is, sanitize it
+$city = filter_var( $_POST['city'], FILTER_SANITIZE_STRING);
+if ((!empty($city)) && (preg_match('/[a-z\.\s]/i', $city)) &&
+ (strlen($city) <= 30)) {
+ //Sanitize the trimmed city
+ $citytrim = $city;
+ }else{
+ $errors[] = 'Missing city. Only alphabetic, period and space. Max 30.';
+ }
+//Is the state or country present? If it is, sanitize it
+$state_country = filter_var( $_POST['state_country'], FILTER_SANITIZE_STRING);
+if ((!empty($state_country)) && (preg_match('/[a-z\.\s]/i', $state_country)) &&
+ (strlen($state_country) <= 30)) {
+ //Sanitize the trimmed state or country
+ $state_countrytrim = $state_country;
+ }else{
+ $errors[] = 'Missing state/country. Only alphabetic, period and space. Max 30.';
+ }
+//Is the zip code or post code present? If it is, sanitize it
+$zcode_pcode = filter_var( $_POST['zcode_pcode'], FILTER_SANITIZE_STRING);
+$string_length = strlen($zcode_pcode);
+if ((!empty($zcode_pcode)) && (preg_match('/[a-z0-9\s]/i', $zcode_pcode)) &&
+ ($string_length <= 30) && ($string_length >= 5)) {
+ //Sanitize the trimmed zcode_pcode
+ $zcode_pcodetrim = $zcode_pcode;
+ }else{
+ $errors[] = 'Missing zip code or post code. Alphabetic, numeric, space only max 30 characters';
+ }
+//Is the phone number present? If it is, sanitize it
+$phone = filter_var( $_POST['phone'], FILTER_SANITIZE_STRING);
+if ((!empty($phone)) && (strlen($phone) <= 30)) {
+ //Sanitize the trimmed phone number
+ $phonetrim = (filter_var($phone, FILTER_SANITIZE_NUMBER_INT));
+ $phonetrim = preg_replace('/[^0-9]/', '', $phonetrim);
+ }else{
+ $phonetrim = NULL;
+ }
+ if (empty($errors)) { // If everything's OK. #2
+ $query = 'UPDATE users SET title=?, first_name=?, last_name=?, address1=?,';
+ $query .= ' address2=?, city=?, state_country=?, zcode_pcode=?,';
+ $query .= ' phone=?';
+ $query .= ' WHERE userid=? LIMIT 1';
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind values to SQL Statement
+
+ mysqli_stmt_bind_param($q, 'ssssssssss', $titletrim, $first_nametrim, $last_nametrim,
+ $address1trim, $address2trim, $citytrim, $state_countrytrim,
+ $zcode_pcodetrim, $phonetrim, $id);
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ if (mysqli_stmt_affected_rows($q) == 1) { // Update OK
+
+ // Echo a message if the edit was satisfactory:
+ echo '
The user has been edited.
';
+ } else { // Echo a message if the query failed.
+ echo '
The user could not be edited due to a system error.';
+ echo ' We apologize for any inconvenience.
'; // Public message.
+ //echo '
' . mysqli_error($dbcon) . ' Query: ' . $q . '
'; // Debugging message.
+ // Message above is only for debug and should not display sql in live mode
+ }
+ } else { // Display the errors.
+ echo '
The following error(s) occurred: ';
+ foreach ($errors as $msg) { // Echo each error.
+ echo " - $msg \n";
+ }
+ echo '
Please try again.
';
+ } // End of if (empty($errors))section.
+} // End of the conditionals
+// Select the user's information to display in textboxes: #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query = "SELECT * FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'i', $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+ $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+ // Get the user's information:
+
+ // Create the form:
+?>
+
Edit User
+
Items marked with an asterisk * are required
+
+This page has been accessed in error.';
+}
+mysqli_stmt_free_result($q);
+mysqli_close($dbcon);
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try later";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again later";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_edit_record.php b/Ch06/finalpostal/process_edit_record.php
new file mode 100644
index 0000000..ab7dd33
--- /dev/null
+++ b/Ch06/finalpostal/process_edit_record.php
@@ -0,0 +1,235 @@
+This page has been accessed in error.';
+ include ('footer.php');
+ exit();
+}
+
+require ('./mysqli_connect.php');
+// Has the form been submitted?
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $errors = array();
+// Trim the first name
+ $first_name = filter_var( $_POST['first_name'], FILTER_SANITIZE_STRING);
+if ((!empty($first_name)) && (preg_match('/[a-z\s]/i',$first_name)) &&
+ (strlen($first_name) <= 30)) {
+ //Sanitize the trimmed first name
+ $first_nametrim = $first_name;
+ }else{
+ $errors[] = 'First name missing or not alphabetic and space characters. Max 30';
+ }
+ //Is the last name present? If it is, sanitize it
+ $last_name = filter_var( $_POST['last_name'], FILTER_SANITIZE_STRING);
+if ((!empty($last_name)) && (preg_match('/[a-z\-\s\']/i',$last_name)) &&
+ (strlen($last_name) <= 40)) {
+ //Sanitize the trimmed last name
+ $last_nametrim = $last_name;
+ }else{
+ $errors[] = 'Last name missing or not alphabetic, dash, quote or space. Max 30.';
+ }
+// Check that an email address has been entered
+ $emailtrim = filter_var( $_POST['email'], FILTER_SANITIZE_EMAIL);
+ if ((empty($emailtrim)) || (!filter_var($emailtrim, FILTER_VALIDATE_EMAIL))
+ || (strlen($emailtrim > 60))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+//Is the class present? If it is, sanitize it
+$class = filter_var( $_POST['level'], FILTER_SANITIZE_STRING);
+if ((!empty($class)) && (strlen($class) <= 3)) {
+ //Sanitize the trimmed phone number
+ $classtrim = (filter_var($class, FILTER_SANITIZE_NUMBER_INT));
+ }else{
+ $errors[] = 'Missing Level Selection.';
+ }
+ // Look for the Paid Status:
+ $paid = filter_var( $_POST['paid'], FILTER_SANITIZE_STRING);
+ if (empty($paid)) {
+ $errors[] = 'You forgot to enter the paid status.';
+ }
+ if (!(($paid == "No") || ($paid == "Yes"))) {
+ $errors[] = "Paid must be No or Yes.";
+ }
+ if (empty($errors)) { // If everything's OK.
+ $q = mysqli_stmt_init($dbcon);
+ $query = 'SELECT userid FROM users WHERE email=? AND userid !=?';
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'si', $email, $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+ $result = mysqli_stmt_get_result($q);
+
+ if (mysqli_num_rows($result) == 0) { // e-mail does not exist in another record
+ $query = 'UPDATE users SET first_name=?, last_name=?, email=?,';
+ $query .= ' class=?, paid=?';
+ $query .= ' WHERE userid=? LIMIT 1';
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind values to SQL Statement
+
+ mysqli_stmt_bind_param($q, 'sssssi', $first_name, $last_name, $email, $class, $paid, $id);
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ if (mysqli_stmt_affected_rows($q) == 1) { // Update OK
+
+ // Echo a message if the edit was satisfactory:
+ echo '
The user has been edited.
';
+ } else { // Echo a message if the query failed.
+ echo '
The user could not be edited. Did you change anything?';
+ echo ' We apologize for any inconvenience.
'; // Public message.
+ //echo '
' . mysqli_error($dbcon) . ' Query: ' . $q . '
'; // Debugging message.
+ // Message above is only for debug and should not display sql in live mode
+ }
+ } else { // Already registered.
+ echo '
The email address has already been registered.
';
+ }
+ } else { // Display the errors.
+ echo '
The following error(s) occurred: ';
+ foreach ($errors as $msg) { // Echo each error.
+ echo " - $msg \n";
+ }
+ echo '
Please try again.
';
+ } // End of if (empty($errors))section.
+} // End of the conditionals
+// Select the user's information to display in textboxes: #3
+
+ $q = mysqli_stmt_init($dbcon);
+ $query =
+ "SELECT first_name, last_name, email, class, paid FROM users WHERE userid=?";
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'i', $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+
+ $result = mysqli_stmt_get_result($q);
+
+ $row1 = mysqli_fetch_array($result, MYSQLI_ASSOC);
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+ // Get the user's information:
+
+ // Create the form:
+?>
+
Edit a Record
+
+This page has been accessed in error.';
+}
+mysqli_stmt_free_result($q);
+mysqli_close($dbcon);
+}
+catch(Exception $e)
+{
+ print "The system is busy. Please try later";
+ //print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+ print "The system is currently busy. Please try again later";
+ //print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_temp_view_found_record.php b/Ch06/finalpostal/process_temp_view_found_record.php
new file mode 100644
index 0000000..cd08dfa
--- /dev/null
+++ b/Ch06/finalpostal/process_temp_view_found_record.php
@@ -0,0 +1,70 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, userid FROM users WHERE ";
+$query .= "last_name='Smith' AND first_name='James' ";
+$query .="ORDER BY registration_date ASC ";
+// Perpared statement not needed because string is hard coded
+$result = mysqli_query ($dbcon, $query); // Run the query.
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
';
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_view_found_addresses.php b/Ch06/finalpostal/process_view_found_addresses.php
new file mode 100644
index 0000000..4b42938
--- /dev/null
+++ b/Ch06/finalpostal/process_view_found_addresses.php
@@ -0,0 +1,96 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+$first_name = htmlspecialchars($_POST['first_name'], ENT_QUOTES);
+$last_name = htmlspecialchars($_POST['last_name'], ENT_QUOTES);
+// Since it's a prepared statement below this sanitizing is not needed
+// However, to consistantly retrieve than sanitize is a good habit
+
+$query = "SELECT userid, title, last_name, first_name, ";
+$query .= "address1, address2, city, state_country, zcode_pcode, phone ";
+$query .= "FROM users WHERE ";
+$query .= "last_name=? AND first_name=?";
+
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind values to SQL Statement
+mysqli_stmt_bind_param($q, 'ss', $last_name, $first_name);
+
+// execute query
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Title
+
Last Name
+
First Name
+
Address1
+
Address2
+
City
+
State or Country
+
Zip or Postal Code
+
Phone
+
';
+
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $title = htmlspecialchars($row['title'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $address1 = htmlspecialchars($row['address1'], ENT_QUOTES);
+ $address2 = htmlspecialchars($row['address2'], ENT_QUOTES);
+ $city = htmlspecialchars($row['city'], ENT_QUOTES);
+ $state_country = htmlspecialchars($row['state_country'], ENT_QUOTES);
+ $zcode_pcode = htmlspecialchars($row['zcode_pcode'], ENT_QUOTES);
+ $phone = htmlspecialchars($row['phone'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/process_view_found_record.php b/Ch06/finalpostal/process_view_found_record.php
new file mode 100644
index 0000000..a56dc08
--- /dev/null
+++ b/Ch06/finalpostal/process_view_found_record.php
@@ -0,0 +1,89 @@
+If no record is shown, ';
+echo 'this is because you had an incorrect ';
+echo ' or missing entry in the search form.';
+echo ' Click the back button on the browser and try again';
+$first_name = htmlspecialchars($_POST['first_name'], ENT_QUOTES);
+$last_name = htmlspecialchars($_POST['last_name'], ENT_QUOTES);
+// Since it's a prepared statement below this sanitizing is not needed
+// However, to consistantly retrieve than sanitize is a good habit
+
+$query = "SELECT last_name, first_name, email, ";
+$query .= "DATE_FORMAT(registration_date, '%M %d, %Y')";
+$query .=" AS regdat, class, paid, userid FROM users WHERE ";
+$query .= "last_name=? AND first_name=? ";
+$query .="ORDER BY registration_date ASC ";
+
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind values to SQL Statement
+mysqli_stmt_bind_param($q, 'ss', $last_name, $first_name);
+
+// execute query
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran, display the records.
+// Table header.
+echo '
+
+
Edit
+
Delete
+
Last Name
+
First Name
+
Email
+
Date Registered
+
Class
+
Paid
+
';
+// Fetch and display the records:
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ // Remove special characters that might already be in table to
+ // reduce the chance of XSS exploits
+ $user_id = htmlspecialchars($row['userid'], ENT_QUOTES);
+ $last_name = htmlspecialchars($row['last_name'], ENT_QUOTES);
+ $first_name = htmlspecialchars($row['first_name'], ENT_QUOTES);
+ $email = htmlspecialchars($row['email'], ENT_QUOTES);
+ $registration_date = htmlspecialchars($row['regdat'], ENT_QUOTES);
+ $class = htmlspecialchars($row['class'], ENT_QUOTES);
+ $paid = htmlspecialchars($row['paid'], ENT_QUOTES);
+ echo '
'; // Close the table.
+ //
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Public message:
+ echo '
The current users could not be retrieved.';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ //echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+ //Show $q is debug mode only
+} // End of if ($result). Now display the total number of records/members.
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e)
+{
+print "The system is currently busy. Please try later.";
+//print "An Exception occurred.Message: " . $e->getMessage();
+}catch(Error $e)
+{
+print "The system us busy. Please try later.";
+//print "An Error occured. Message: " . $e->getMessage();
+}
+?>
\ No newline at end of file
diff --git a/Ch06/finalpostal/register-page.php b/Ch06/finalpostal/register-page.php
new file mode 100644
index 0000000..9b35e6b
--- /dev/null
+++ b/Ch06/finalpostal/register-page.php
@@ -0,0 +1,245 @@
+
+
+
+ Register Page
+
+
+
+
+
+
+
+
+
+
+getMessage();
+ print "The system is busy please try later";
+ }
+catch(Error $e)
+{
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+}
+?>
+
+
diff --git a/Ch06/finalpostal/register-view-users.php b/Ch06/finalpostal/register-view-users.php
new file mode 100644
index 0000000..57aea19
--- /dev/null
+++ b/Ch06/finalpostal/register-view-users.php
@@ -0,0 +1,93 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are the registered users
+
+
+
Name
Date Registered
';
+// Fetch and print all the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+echo '
' . $row['name'] . '
' . $row['regdat'] . '
'; }
+ echo ''; // Close the table so that it is ready for displaying.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ }
+ catch(Error $e)
+ {
+ //print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try again later.";
+ }
+?>
+
+
+
+
diff --git a/Ch06/finalpostal/temp_view_found_record.php b/Ch06/finalpostal/temp_view_found_record.php
new file mode 100644
index 0000000..8a78417
--- /dev/null
+++ b/Ch06/finalpostal/temp_view_found_record.php
@@ -0,0 +1,55 @@
+
+
+
+
+ Template for an interactive web page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
These are found users
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ch06/finalpostal/verify.js b/Ch06/finalpostal/verify.js
new file mode 100644
index 0000000..b5a9501
--- /dev/null
+++ b/Ch06/finalpostal/verify.js
@@ -0,0 +1,12 @@
+function checked() {
+ if (document.getElementById('password1').value ==
+ document.getElementById('password2').value) {
+ document.getElementById('message').style.color = 'green';
+ document.getElementById('message').innerHTML = 'Passwords match';
+ return true;
+ } else {
+ document.getElementById('message').style.color = 'red';
+ document.getElementById('message').innerHTML = 'Passwords do not match';
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/Ch06/finalpostal/view_found_address.php b/Ch06/finalpostal/view_found_address.php
new file mode 100644
index 0000000..ef2ae9b
--- /dev/null
+++ b/Ch06/finalpostal/view_found_address.php
@@ -0,0 +1,123 @@
+
+
+
+
+View found address page
+
+
+
+
+
+
+
+
+
+
+
+
+
Search Address Result
+If no record is shown, this is because you had an incorrect ';
+echo 'or missing entry in the search form. ';
+echo 'Or the person is not registered with us.';
+echo ' Please click the Addresses button and try again';
+try {
+$query = "SELECT user_id, title, lname, fname, addr1, addr2, ";
+$query .= "city, state_country, zcode_pcode, phone FROM users ";
+$query .= "WHERE fname=? AND lname=?";
+// prepared statement to protect $lname $fname values
+$q = mysqli_stmt_init($dbcon);
+mysqli_stmt_prepare($q, $query);
+
+// bind values to SQL Statement
+mysqli_stmt_bind_param($q, 'ss', $fname, $lname);
+
+// execute query
+
+mysqli_stmt_execute($q);
+
+$result = mysqli_stmt_get_result($q);
+
+if ($result) { // If it ran, display the records.
+// Table header. #2
+
+echo '
+
Edit
+
Title
+
Last Name
+
First Name
+
Addrs1
+
Addrs2
+
City
+
State_Country
+
zcode_pcode
+
Phone
+
';
+// Fetch and display the records: #3
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+ echo '
'; // Close the table.
+ mysqli_free_result ($result); // Free up the resources.
+} else { // If it failed to run
+// Public message:
+ echo '
The current users could not be retrieved. ';
+ echo 'We apologize for any inconvenience.
';
+ // Debugging message:
+ echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+} // End of if ($result). Now display the total number of records/members.
+$q = "SELECT COUNT(user_id) FROM users";
+$result = @mysqli_query ($dbcon, $q);
+$row = @mysqli_fetch_array ($result, MYSQLI_NUM);
+$members = $row[0];
+mysqli_close($dbcon); //Close the database connection.
+echo "
';
+ }
+ echo ''; // Close the table.
+ // #7
+ mysqli_free_result ($result); // Free up the resources.
+}
+else { // If it did not run OK.
+// Error message:
+echo '
The current users could not be retrieved. We apologize';
+echo ' for any inconvenience.
';
+// Debug message:
+// echo '
' . mysqli_error($dbcon) . '
Query: ' . $q . '
';
+exit;
+} // End of if ($result)
+mysqli_close($dbcon); // Close the database connection.
+}
+catch(Exception $e) // We finally handle any problems here
+ {
+ // print "An Exception occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ // $date = date(‘m.d.y h:i:s’);
+ // $errormessage = $e->getMessage();
+ // $eMessage = $date . “ | Exception Error | “ , $errormessage . |\n”;
+ // error_log($eMessage,3,ERROR_LOG);
+ // e-mail support person to alert there is a problem
+ // error_log(“Date/Time: $date – Exception Error, Check error log for
+//details”, 1, noone@helpme.com, “Subject: Exception Error \nFrom: Error Log ” . “\r\n”);
+
+ }
+ catch(Error $e)
+ {
+ // print "An Error occurred. Message: " . $e->getMessage();
+ print "The system is busy please try later";
+ // $date = date(‘m.d.y h:i:s’);
+ // $errormessage = $e->getMessage();
+ // $eMessage = $date . “ | Error | “ , $errormessage . |\n”;
+ // error_log($eMessage,3,ERROR_LOG);
+ // // e-mail support person to alert there is a problem
+ // error_log(“Date/Time: $date – Error, Check error log for
+//details”, 1, noone@helpme.com, “Subject: Error \nFrom: Error Log ” . “\r\n”);
+
+ }
+?>
+
+
+
+
+ 60))) {
+ $errors[] = 'You forgot to enter your email address';
+ $errors[] = ' or the e-mail format is incorrect.';
+ }
+
+//Is the 1st address present? If it is, sanitize it
+$address1 = filter_var( $_POST['address1'], FILTER_SANITIZE_STRING);
+if ((!empty($address1)) && (preg_match('/[a-z0-9\.\s\,\-]/i', $address1)) &&
+ (strlen($address1) <= 30)) {
+ //Sanitize the trimmed 1st address
+ $address1trim = $address1;
+ }else{
+ $errors[] = 'Missing address. Only numeric, alphabetic, period, comma, dash and space. Max 30.';
+ }
+
+//If the 2nd address is present? If it is, sanitize it #10
+$address2 = filter_var( $_POST['address2'], FILTER_SANITIZE_STRING);
+if ((!empty($address2)) && (preg_match('/[a-z0-9\.\s\,\-]/i', $address2)) &&
+ (strlen($address2) <= 30)) {
+ //Sanitize the trimmed 2nd address
+ $address2trim = $address2;
+ }else{
+ $address2trim = NULL;
+ }
+//Is the city present? If it is, sanitize it
+$city = filter_var( $_POST['city'], FILTER_SANITIZE_STRING);
+if ((!empty($city)) && (preg_match('/[a-z\.\s]/i', $city)) &&
+ (strlen($city) <= 30)) {
+ //Sanitize the trimmed city
+ $citytrim = $city;
+ }else{
+ $errors[] = 'Missing city. Only alphabetic, period and space. Max 30.';
+ }
+//Is the state or country present? If it is, sanitize it
+$state_country = filter_var( $_POST['state_country'], FILTER_SANITIZE_STRING);
+if ((!empty($state_country)) && (preg_match('/[a-z\.\s]/i', $state_country)) &&
+ (strlen($state_country) <= 30)) {
+ //Sanitize the trimmed state or country
+ $state_countrytrim = $state_country;
+ }else{
+ $errors[] = 'Missing state/country. Only alphabetic, period and space. Max 30.';
+ }
+//Is the zip code or post code present? If it is, sanitize it
+$zcode_pcode = filter_var( $_POST['zcode_pcode'], FILTER_SANITIZE_STRING);
+$string_length = strlen($zcode_pcode);
+if ((!empty($zcode_pcode)) && (preg_match('/[a-z0-9\s]/i', $zcode_pcode)) &&
+ ($string_length <= 30) && ($string_length >= 5)) {
+ //Sanitize the trimmed zcode_pcode
+ $zcode_pcodetrim = $zcode_pcode;
+ }else{
+ $errors[] = 'Missing zip code or post code. Alphabetic, numeric, space only max 30 characters';
+ }
+//Is the phone number present? If it is, sanitize it
+$phone = filter_var( $_POST['phone'], FILTER_SANITIZE_STRING);
+if ((!empty($phone)) && (strlen($phone) <= 30)) {
+ //Sanitize the trimmed phone number
+ $phonetrim = (filter_var($phone, FILTER_SANITIZE_NUMBER_INT));
+ $phonetrim = preg_replace('/[^0-9]/', '', $phonetrim);
+ }else{
+ $phonetrim = NULL;
+ }
+ if (empty($errors)) { // If everything's OK.
+ // make the query
+ $q = mysqli_stmt_init($dbcon);
+ $query = 'SELECT userid FROM users WHERE email=? AND userid !=?';
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'si', $emailtrim, $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+ $result = mysqli_stmt_get_result($q);
+
+if (mysqli_num_rows($result) == 0) { // e-mail does not exist in another record
+ // Make the update query: #5
+
+ $query = 'UPDATE users SET title=?, first_name=?, last_name=?, email=?, ';
+ $query .='address1=?, address2=?, city=?, state_country=?, zcode_pcode=?, ';
+ $query .='phone=?';
+ $query .= ' WHERE userid=?';
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind values to SQL Statement
+
+ mysqli_stmt_bind_param($q, 'ssssssssssi', $titletrim, $first_nametrim, $last_nametrim,
+ $emailtrim, $address1trim, $address2trim, $citytrim, $state_countrytrim,
+ $zcode_pcodetrim, $phonetrim, $id);
+ // execute query
+
+ mysqli_stmt_execute($q);
+ if (mysqli_stmt_affected_rows($q) == 1) { // Update OK
+
+ // Echo a message if the edit was satisfactory:
+ $errorstring = 'The user has been edited.';
+ echo "
$errorstring
";
+ } else { // Echo a message if the query failed.
+ $errorstring = 'The user could not be edited. Did you change anything?';
+ $errorstring .= ' We apologize for any inconvenience.'; // Public message.
+ echo "
$errorstring
";
+ //echo '
' . mysqli_error($dbcon) . ' Query: ' . $q . '
'; // Debugging message.
+ // Message above is only for debug and should not display sql in live mode
+ }
+ }
+ } else { // Display the errors.
+ // ---------------Process User Errors---------------
+ // Display the users entry errors
+ $errorstring = 'Error! The following error(s) occurred: ';
+ foreach ($errors as $msg) { // Print each error.
+ $errorstring .= " - $msg \n";
+ }
+ $errorstring .= 'Please try again.';
+ echo "
$errorstring
";
+ }// End of if (empty($errors)) IF.
+} // End of the conditionals
+// Select the user's information: #6
+
+$query = "SELECT title, first_name, last_name, email, address1, address2, city, state_country, zcode_pcode, phone ";
+$query .=" FROM users WHERE userid=?";
+// id was retrieved from database prepared not needed
+ $q = mysqli_stmt_init($dbcon);
+ mysqli_stmt_prepare($q, $query);
+
+ // bind $id to SQL Statement
+ mysqli_stmt_bind_param($q, 'i', $id);
+
+ // execute query
+
+ mysqli_stmt_execute($q);
+ $result = mysqli_stmt_get_result($q);
+
+if (mysqli_num_rows($result) == 1) { // Valid user ID, display the form.
+ // Get the user's information:
+ $row = mysqli_fetch_array ($result, MYSQLI_ASSOC);
+ // Create the form: #7
+
+
+?>
+
+
+
Edit Your Account Details
+
For your own security, please remember to log out!
\ No newline at end of file
diff --git a/Ch07/migrate/includes/header-admin.php b/Ch07/migrate/includes/header-admin.php
new file mode 100644
index 0000000..50c305b
--- /dev/null
+++ b/Ch07/migrate/includes/header-admin.php
@@ -0,0 +1,15 @@
+
+
+
+
+
Header Goes Here
+
+
diff --git a/Ch07/migrate/includes/header-members-account.php b/Ch07/migrate/includes/header-members-account.php
new file mode 100644
index 0000000..6585f39
--- /dev/null
+++ b/Ch07/migrate/includes/header-members-account.php
@@ -0,0 +1,8 @@
+
diff --git a/Ch07/migrate/includes/header-members.php b/Ch07/migrate/includes/header-members.php
new file mode 100644
index 0000000..3bf6406
--- /dev/null
+++ b/Ch07/migrate/includes/header-members.php
@@ -0,0 +1,12 @@
+
+
+
+
+
Header Goes Here
+
+
\ No newline at end of file
diff --git a/Ch07/migrate/includes/header-thanks.php b/Ch07/migrate/includes/header-thanks.php
new file mode 100644
index 0000000..b0b0b07
--- /dev/null
+++ b/Ch07/migrate/includes/header-thanks.php
@@ -0,0 +1,12 @@
+
+
\ No newline at end of file
diff --git a/Ch07/migrate/includes/header1.php b/Ch07/migrate/includes/header1.php
new file mode 100644
index 0000000..11a86b0
--- /dev/null
+++ b/Ch07/migrate/includes/header1.php
@@ -0,0 +1,73 @@
+