E-Book, Englisch, 561 Seiten
West / Prettyman Practical PHP 7, MySQL 8, and MariaDB Website Databases
2. ed
ISBN: 978-1-4842-3843-1
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
A Simplified Approach to Developing Database-Driven Websites
E-Book, Englisch, 561 Seiten
ISBN: 978-1-4842-3843-1
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
Build interactive, database-driven websites with PHP 7, MySQL 8, and MariaDB. The focus of this book is on getting you up and running as quickly as possible with real-world applications. In the first two chapters, you will set up your development and testing environment, and then build your first PHP and MariaDB or MySQL database-driven website. You will then increase its sophistication, security, and functionality throughout the course of the book. The PHP required is taught in context within each project so you can quickly learn how PHP integrates with MariaDB and MySQL to create powerful database-driven websites. Each project is fully illustrated, so you will see clearly what you are building as you create your own database-driven website. You will build a form for registering users, and then build an interface so that an administrator can view and administer the user database. You will create a message board for users and a method for emailing them. You will also learn the best practices for ensuring that your website databases are secure. Later chapters describe how to create a product catalog, and a simple e-commerce site. You will also discover how to migrate a database to a remote host. The final chapter will demonstrate the advantages of migrating to Oracle's MySQL 8. You will be shown step by step migration directions along with a demonstration of the tools available in SQL Workbench. Because you are building the interactive pages yourself, you will know exactly how MySQL, MariaDB, and PHP all work together, and you will be able to add database interactivity to your own websites with ease.
What You Will Learn
Build a secure database-driven website using PHP 7, MySQL 8, and MariaDB
Create a product catalog
Write a message board
Move towards e-commerce
Employ security and validation measures
Migrate to Oracle's MySQL 8 Server platform
Who This Book Is For Web developers with HTML, CSS and a limited Bootstrap experience. Readers need little to no prior experience with PHP and MySQL.
Adrian W. West is an active web design and development consultant at amwebdesign.co.uk. He also writes monthly computer help articles in two local magazines. Adrian is the author of Practical HTML5 Projects, also published by Apress. Frustrated by the over-complicated MySQL manuals that assumed the reader would fill in the many gaps in the instructions, he researched, tested and developed a fully explained and simplified method to eliminate the difficulties he experienced; this book is the result.
Steve Prettyman earned his bachelor of arts degree in education from Oglethorpe University in 1979. He quickly began his teaching career as a high school mathematics instructor while continuing his education by earning a master's degree in business information systems from Georgia State University (1985). Since then, Steve has spent over 30 years in the IT industry. The last, almost 20 years, he has been an instructor and professor at Chattahoochee Technical College, Kennesaw State University, and Southern Polytechnic State University. He is currently the Computer Science Department Chair for Florida Keys Community College, Key West, Florida. His primary teaching responsibilities include programming, web design, and web application development.
Autoren/Hrsg.
Weitere Infos & Material
1;Contents;4
2;About the Authors;14
3;Acknowledgments;15
4;Introduction;16
5;Chapter 1: Create and Test a Database and Table;20
5.1;Defining Developer, Administrator, and User;21
5.1.1;Defining Interactive Websites;21
5.1.1.1;Using MariaDB or MySQL Only for Interactive Database Tables;22
5.1.1.2;Methods for Developing and Maintaining Databases;22
5.1.1.2.1;A Brief Look Inside Web Server Communication;22
5.1.1.3;A Free Development Platform for Testing;24
5.1.1.4;Using XAMPP on Your Own Computer;24
5.1.1.4.1;Will I Be Able to Transfer the Database from XAMPP or EasyPHP to a Remote Host?;25
5.1.1.5;Downloading and Installing XAMPP;25
5.1.1.5.1;Starting XAMPP;28
5.1.1.6;Closing XAMPP;29
5.1.1.6.1;Where Is MariaDB and MySQL 8?;30
5.1.1.7;Using EasyPHP on Your Own Computer;31
5.1.1.7.1;Download and Install EasyPHP;31
5.1.1.7.2;Starting EasyPHP;31
5.1.1.7.3;Closing EasyPHP;32
5.1.1.7.4;phpMyAdmin Security;32
5.1.1.8;Accessing phpMyAdmin Directly;36
5.1.1.9;The Familiar Bits;37
5.1.1.10;Planning a Database: The Essential First Step;39
5.1.1.11;Creating a Database Using phpMyAdmin;40
5.1.1.11.1;Create a Table Using phpMyAdmin;43
5.1.1.12;The SQL Alternative;46
5.1.1.13;Deleting Databases and Tables;49
5.2;Summary;50
6;Chapter 2: Create Web Pages That Interact with Users;51
6.1;Creating the Folder for Holding the Database Pages;52
6.2;Creating the Temporary Template;52
6.3;Introducing the PHP include() Function;54
6.3.1;The Included Header File;55
6.3.2;The Included Menu File;57
6.3.3;The Included Information Column;58
6.3.4;The Included Footer File;59
6.3.4.1;How Does the Server Process the Page?;60
6.4;The Interactive Version of the Template;60
6.5;Connecting to the Database;62
6.5.1;Explanation of the Code;63
6.5.2;The Registration Page;65
6.5.2.1;Explanation of the Code;68
6.5.2.2;Explanation of the Code;72
6.6;The PHP Keyword echo;76
6.7;The “Thank You” Page;76
6.8;Displaying Error Messages That Are Collected in an Array;78
6.9;Hashing the Password;79
6.10;Viewing Members’ Records;79
6.11;The View Users Page;79
6.11.1;Explanation of the Code;82
6.12;The Change Password Page;83
6.12.1;Explanation of the Code;85
6.12.2;Explanation of the Code;87
6.13;Confirming a Successful Password Change;90
6.13.1;Testing the Tutorial’s Pages;90
6.14;More About Arrays;91
6.15;Summary;92
7;Chapter 3: Create Login/Logout Functionality for Members and an Administrator;93
7.1;Creating the logindb Database and users Table;94
7.2;Removing or Replacing Redundant Menu Buttons in the Headers;95
7.2.1;Adding a Login Button to the Home Page Header;96
7.2.2;Removing Redundant Buttons from the Registration and New Password Headers;97
7.2.3;The Revised Registration Page;97
7.2.4;The New Header for the New Password Page;98
7.2.5;A New Header Menu for the Members page;100
7.2.6;Amend the Header for the “Thank You” Page;100
7.3;The Registration Page and Undesirable Characters;102
7.3.1;Explanation of the Code;104
7.3.2;Registering Some Members;105
7.4;Differentiating Between Two Types of Membership;106
7.5;Creating User Levels to Limit Access to Private Pages;106
7.6;Log In;109
7.6.1;The Header for the Login Page;109
7.6.2;The Login Page;110
7.6.3;Explanation of the Code;112
7.6.4;Explanation of the Code;114
7.6.5;Sessions;117
7.7;A Members-Only Page;119
7.7.1;Explanation of the Code;121
7.8;Planning the Administrator’s Role;122
7.8.1;A New Header for the Administration Page;123
7.8.1.1;The Administrator’s Page;124
7.8.1.2;Explanation of the Code;125
7.8.1.3;The Logout Page;125
7.8.1.4;Explanation of the Code;126
7.9;Testing the Login/Logout Function;127
7.9.1;Amending and Deleting Individual Records;127
7.10;Summary;128
8;Chapter 4: Create an Administration Interface;129
8.1;The Administration Database;129
8.1.1;The Users Table;131
8.2;Revising the View Users Page to Include Editing and Deleting;133
8.2.1;Explanation of the Code;136
8.3;Displaying Pages of Records (Pagination);139
8.3.1;Explanation of the Code;143
8.4;Planning the Search Criteria;146
8.5;A Temporary Search Page for Displaying Specified Members;146
8.5.1;Explanation of the Code;149
8.6;The Search Form;150
8.6.1;Explanation of the Code;152
8.7;The Final Form Handler for Receiving Search Form Input;153
8.7.1;Explanation of the Code;155
8.8;Editing Records;157
8.8.1;Explanation of the Code;160
8.8.2;Deleting Records;163
8.8.3;Explanation of the Code;166
8.9;Summary;168
9;Chapter 5: Expand and Enrich Your Website;169
9.1;Creating a New Database, a Table with 15 Columns, and a Price Table;169
9.1.1;Creating the File for Connecting to the Database;170
9.1.2;Creating the Tables;171
9.1.3;Using ENUM;172
9.2;The Importance of Documentation;172
9.3;Extending the Registration Form and Adding a Pull-Down Menu;174
9.3.1;Always Announce Prices and Fee Payments Up-Front;175
9.3.2;Explanation of the Code;180
9.3.3;Explanation of the Code;185
9.4;Adding PayPal Debit/Credit Card Images;186
9.5;Including PayPal on the “Thank You” Page;186
9.5.1;Explanation of the Code;190
9.6;Registering Some Members;191
9.6.1;A Small Amendment to the Login Page;193
9.7;Amending the Administrator’s Header;193
9.8;Adding Class and Paid to the admin_view_users Table;195
9.8.1;Explanation of the Code;198
9.9;Searching and Editing Records;199
9.9.1;Explanation of the Code;202
9.9.2;Modifying the Form for Editing Records;202
9.10;Summary;208
10;Chapter 6: Add the Finishing Touches: Security and Validation;209
10.1;Creating the Database;209
10.1.1;Creating the File for Connecting to the Database;210
10.2;Creating the users Table by Importing a SQL Dump File;211
10.2.1;Registering Some Members Manually;213
10.3;Adding a Title Column to the users Table;215
10.3.1;Creating the Prices Table by Importing a SQL Dump File;217
10.4;Tidying Up the Folders and Filing System;218
10.5;Degrees of Security;218
10.5.1;Adding a Layer of Security;218
10.5.2;An Increased Layer of Protection;220
10.6;Validation and Sanitization;220
10.6.1;The filter_var() Function;220
10.6.2;Validation;220
10.6.3;Sanitization;222
10.6.4;Validating Telephone Numbers;223
10.7;A Safer Registration Page;223
10.7.1;Explanation of the Code;231
10.7.2;Explanation of the Code;238
10.8;Searching for a Title, an Address, or a Telephone Number;239
10.8.1;Explanation of the Code;242
10.8.2;Viewing the Retrieved Title, Address, and Phone Number;243
10.8.3;Explanation of the Code;245
10.8.4;Editing the Title, Addresses, and Telephone Numbers;246
10.8.5;Explanation of the Code;253
10.9;Summary;254
11;Chapter 7: Migrate to a Host and Back Up Your Website Database;255
11.1;Making Last-Minute Changes;255
11.1.1;Creating a New Database;256
11.1.1.1;Details of the Downloaded File for Connecting to the Database;257
11.1.2;Allowing Members to Update Their Own Records;258
11.1.2.1;Explanation of the Code;270
11.1.3;A Secure Feedback Form;272
11.1.3.1;What Does a Feedback Reply Look Like?;272
11.1.4;The Feedback Form;273
11.1.4.1;Explanation of the Code;278
11.1.4.2;Explanation of the Code;282
11.1.5;The “Thank You” Page and the Error Messages;284
11.2;A Common Header;287
11.2.1;Explanation of the Code;289
11.3;Logging Exceptions and Error;290
11.4;Migrating the Database and Tables to a Remote Host;292
11.4.1;A Puzzling Error Message;293
11.4.2;Creating and Exporting the SQL File;293
11.4.2.1;To Create a Dump File of a Table or Tables;293
11.4.2.2;What Does a SQL Dump Look Like?;295
11.4.2.3;Investigate the Remote Host’s Server;298
11.4.3;Using the GUIs on a Remote Host’s Server;299
11.4.4;Connecting to the Database on the Remote Host;300
11.4.5;Securely Uploading the mysqli_connection.php File;301
11.4.6;Uploading the Interactive Pages to the Host;303
11.5;Backing Up Your Database;304
11.6;Summary;304
12;Chapter 8: Create a Product Catalog;305
12.1;Preparing the Database and Administration Plan;305
12.2;Creating a New Database;306
12.3;Creating the File for Connecting to the Database;307
12.4;Security;308
12.5;Creating a Home Page with Search Capability;310
12.5.1;The Header for the Majority of the Pages;311
12.5.2;The Home Page Code;312
12.6;Displaying the Catalog;314
12.6.1;Explanation of the Code;320
12.7;The Header for the Page of Search Results;321
12.8;Creating the House Details Page;322
12.8.1;Explanation of Code;326
12.9;Creating the Admin/Adding a House Page;327
12.10;The Header for the Administrator’s Page;336
12.11;Administrator’s View of the Entire Stock of Houses for Sale;338
12.12;The Administrator’s Search Page;343
12.12.1;The Result of a Search;345
12.13;The Contact Us Page;346
12.14;Summary;352
13;Chapter 9: Join Multiple Tables and Other Enhancements;353
13.1;Introduction to Multiple Tables;353
13.1.1;Normalization;354
13.1.2;Creating the Database and Tables;355
13.1.3;Viewing the Connection File;356
13.1.3.1;Creating a Second Table;357
13.1.3.2;Foreign Keys;357
13.1.4;Preparing the Tables for Joining;357
13.1.5;Populating the Two Tables;358
13.2;Joining Data from the Two Tables;360
13.2.1;Creating the Third Table;363
13.2.2;Creating Pages to Display the Data from Your Joined Tables;365
13.2.3;The Home Page;365
13.2.4;The Main Menu for the Pages;367
13.2.5;The Header for All the Pages;368
13.2.6;The Page for Viewing the Birds;369
13.2.6.1;Explanation of the Code;373
13.2.7;The Page for Viewing the Locations and Habitats of the Reserves;373
13.2.7.1;Displaying Data from the Joined Tables;376
13.2.7.2;Creating a Page to Display the Three Joined Tables;380
13.2.7.3;Explanation of the Code;384
13.3;Payments by Check;384
13.3.1;A Choice of Payment Method;385
13.3.1.1;The Check Payment;389
13.3.1.2;Explanation of the Code;392
13.4;Printing Online Forms;393
13.5;Summary;394
14;Chapter 10: Create a Message Board;395
14.1;The Plan;395
14.2;Creating the Database;396
14.3;Creating the Tables;396
14.4;Creating the Second Table;397
14.5;Creating the Registration Form;403
14.5.1;The “Thank You” Page;411
14.6;Populating the Members Table;412
14.7;The Login Page;413
14.7.1;Explanation of the Code;415
14.8;Logging Out;418
14.9;Creating a Gateway to a Choice of Quotes;418
14.10;The Form for Posting Quotations;420
14.10.1;Explanation of the Code;423
14.10.1.1;Processing the Postings;424
14.10.2;Explanation of the Code;425
14.11;Posting Some Quotations;426
14.12;The Comical Quotes Page;427
14.12.1;Explanation of the Code;429
14.12.1.1;The Header for the Comical Quotes Page;430
14.12.2;The Wise Quotes Page;431
14.12.3;Explanation of the Code;433
14.12.3.1;The Header for the Wise Quotes Page;434
14.13;Adding Search Facilities;435
14.13.1;Explanation of the Code;437
14.14;The Header for ViewPosts.php;438
14.15;Searching for Specific Words or Phrases;439
14.15.1;The Full Text Search Form;440
14.16;Displaying the Search Results;442
14.16.1;Explanation of the Code;444
14.16.2;The Header for the quotes_found Page;445
14.17;Enhancing the Message Board;446
14.17.1;Converting the Message Board to a Forum;446
14.18;Summary;447
15;Chapter 11: E-commerce: A Brief Introduction;448
15.1;Security Warning;450
15.2;The Plan;450
15.3;Creating the PayPal Cart Site;451
15.3.1;Creating the PayPal Cart Database and Tables;451
15.3.2;Viewing the Connection File;452
15.3.3;Populating the PayPal Cart Tables;452
15.3.4;The PayPal Cart Home Page;455
15.3.5;Using the PayPal Cart Home Page to Search for Paintings;458
15.3.5.1;Explanation of the Code;460
15.3.6;Integrating with the PayPal Shopping Cart Buttons;461
15.3.6.1;Explanation of the Code;467
15.4;Creating a Custom Cart;467
15.4.1;The Custom Cart Home Page;469
15.4.2;Create the Custom Cart Database and Tables;469
15.4.2.1;Exploring the Custom Shopping Cart;471
15.4.2.2;The Custom Cart Login Page;473
15.4.2.3;Explanation of the Code;477
15.4.3;Retrieving a Forgotten Password;477
15.4.3.1;Explanation of the Code;480
15.4.4;The Custom Cart Search Page;481
15.4.5;Adding Paintings to a Table for a Custom Shopping Cart;482
15.4.5.1;Explanation of the Code;486
15.4.5.2;Explanation of the Code;489
15.4.5.3;Explanation of the Code;493
15.4.6;The Checkout Page;494
15.4.7;The Additional Administrative Tasks;494
15.5;Summary;495
16;Chapter 12: Take a Brief Look at Oracle MySQL 8;496
16.1;Advantages of Upgrading;496
16.2;Installing MySQL 8 Community Server;498
16.3;Exploring the Features of MySQL Workbench;505
16.4;Connecting PHP 7 to the MySQL 8 Community Server;512
16.5;Migrating to MySQL 8 Community Server;515
16.6;Using Our PHP Files with MySQL 8 Community Server;519
16.7;Summary;522
17;Appendix A: Troubleshooting;523
17.1;Browser Quirks;524
17.2;Tables Not Displaying;524
17.3;A Style Change Has No Effect;525
17.4;Included Items Missing from the Display;525
17.5;A Page Fails to Validate;525
17.6;A PayPal Pull-Down Menu Does Not Work;525
17.7;Access Denied;525
17.8;PHP Error Levels;526
17.9;Call to an Undefined Function;526
17.10;Cannot Redeclare Function;526
17.11;Undefined Index or Undefined Variable;526
17.12;Empty Variable Value;527
17.13;Headers Already Sent;527
17.14;Blank Screen;527
17.15;Unexpected End of File in Line xxx;527
17.16;Parse Error and Unexpected Characters;528
17.17;Unexpected T_STRING;528
17.18;Unexpected T_ELSE;529
17.19;Wrong Equal Sign;529
17.20;Failed to Open Stream;529
17.21;Syntax Errors;529
17.22;Warning: Division by Zero;530
17.23;Display Is Not What Was Expected;530
17.24;Reference to a Primary Key Could Not Be Created;530
17.25;Element




