You cannot learn programming by only looking at examples. Please refer to the recommended text book (Murach's PHP and MySQL 3rd Edition) for detailed explanations.
PHP originally stood for Personal Home Page, but it now stands for the recursive acronym "PHP: Hypertext Preprocessor", example here. - Quote from wikipedia.org
Preparation, basic html review
Files / Title | Description | Video |
---|---|---|
Preparation | - Show File Extensions in Windows 8/8.1 | video 00_001 |
- install notepad++ | video 00_002 | |
- Create Screen Captures, Save As PDF Files | video 00_003 | |
html/css page |
- First HTML 5 File - html 5, notepad++, W3C Markup Validator | video html_ex001_basic |
JavaScript page | - Linking HTML & CSS Files | video html_ex003_selector |
Files / Title | Description | Video |
---|---|---|
Setup environment | - install XAMPP | video 11_001, xampp install 1 |
- What if I get this error? "XAMPP, Apache - Error: Apache shutdown unexpectedly" |
||
create alias | - code to create alias |
Files / Title | Description | Video |
---|---|---|
eg001_basic.php eg001_basic.txt |
- comments, php tag in html, decleration of variables | video 11_006, basic php |
eg002_basic.php eg002_basic.txt |
- variables, data types, loops | |
Use W3C Markup Validation Service to validate your php program's html markup validity. | video 11_009, validation, W3C Markup Validator | |
eg003_input.php main.css eg003_input.txt eg003_process.txt |
- get user input, submit form to eg003_process.php - something interesting, a loan calculator from external site (in js) |
|
eg004_function.php eg004_function.txt |
- function | |
eg005_array.php eg005_array.txt |
- simple array | |
eg006_associative_ array.php eg006_associative_ array.txt |
- associative array | |
eg006a_2d_array.php eg006a_2d_array.txt |
- 2d array |
Connect to MySQL database using PDO (PHP Data Objects). Select, insert, update, delete.
Files / Title | Description | Video |
---|---|---|
step 0 create MySQL database, create MySQL user for web access | ||
using MySQL cmd prompt (shell) in XAMPP other sql commands (change root password etc) |
- using cmd prompt (shell) - create another super user (login: "harry"; password: "elbomonkey") |
video 11_030, xampp mysql 1, cmd prompt |
using XAMPP MySQL web interface (phpMyAdmin) |
- Login as "root" (super user) - change "root" password (from "" to "rootpass") - login as another super user |
video 11_031, xampp mysql 2, cmd promot & phpMyAdmin |
step 1 create database, connect to database, and show error if something goes wrong | ||
eg008_create_db.sql |
- create sql file, use phpmyadmin to create database in MySQL DB server - code to alter db engine |
video 11_032, xampp eg008, 1, create database video 11_032a, change db engine (if you hit error in video 11_032) |
eg008a_connect_database.php |
video 11_033, xampp eg008, 2, connect to database | |
eg008b_database_error.php |
||
step 2 insert, update, and delete database records (simple one line SQL statement) | ||
eg008c_select.php |
- sql select statement - simple php example |
video 11_034, xampp eg008, 3, select |
eg008d_insert.php |
- sql insert statement - simple php example |
video 11_035, xampp eg008, 4, insert |
eg008e_update.php |
- sql update statement - simple php example |
video 11_036, xampp eg008, 5, update |
eg008f_delete.php |
- sql delete statement - simple php example |
video 11_037, xampp eg008, 6, delete |
Connect to MySQL database using PDO (PHP Data Objects). Select, insert, update, delete. This example is more complicated than eg008 (simple one statement files).
Files / Title | Description | Video |
---|---|---|
step 0 login to MySQL database | ||
using XAMPP MySQL web interface (phpMyAdmin) | - login: "harry"; password: "elbomonkey" | |
step 1 create database, connect to database, and show error if something goes wrong | ||
eg008_create_db.sql |
- done in eg008 |
|
eg009a_database.php |
video 11_038, xampp eg009, 1, connect to database | |
eg009b_database_error.php |
||
step 2 insert, update, and delete database records (simple one line SQL statement) | ||
eg009c_index.php |
- sql select statement - php program logic |
video 11_039, xampp eg009, 2, index |
eg009d_delete_product.php |
- sql delete statement - php program logic |
video 11_040, xampp eg009, 3, index continue |
eg009e_add_product_form.php |
- sql insert statement - php program logic |
video 11_041, xampp eg009, 4, add product |
eg009f_add_product.php |
video 11_042, xampp eg009, 5, add product | |
eg009g_error.php |
Controller = index.php
Model = database.php; product_db.php; category_db.php
View = product_list.php; product_add.php; database_error.php
Files / Title | Description | Video |
---|---|---|
step 0 create MySQL database, create MySQL user for web access | ||
eg008_create_db.sql |
- done in eg008 - ER diagram |
video 11_043 xampp eg010, 1, MVC pattern |
create 4 subfolders: - product_manager/ - model/ - errors/ - view/ |
index.php is put in "product_manager/" subfolder | |
step 1 create Model (Mvc)= represent the data | ||
model/ |
- create model folder - connect to database |
|
step 1 create View (mVc)= user interface | ||
errors/ database_error.txt header.txt |
- create errors folder - create file, database_error.php includes header.php and footer.php - create view folder - create files, header.php and footer.php includes main.css |
video 11_044 xampp eg010, 2, database_error.php |
step 1 create Controller (mvC)= receive user request | ||
product_manager/index.php |
- include files, use function "get_category_name()" to get category name | video 11_045 xampp eg010, 3, controller |
step 2 expand MVC, add program functions to list products step 2 update/create Model (Mvc)= represent the data |
||
model/ |
- update - create function "get_categories()" to get all category names from database table |
|
model/product_db.php |
- create new file - create function "get_products_by_category()" to get all product names |
|
step 2 update/create Controller (mvC)= receive user request | ||
product_manager/ |
- update - include product_db.php file - use function "get_categories()" to get all category names - use function "get_products_by_category()" to get all product names - include product_list.php (new file below) |
video 11_046 xampp eg010, 4, product list |
product_manager/ |
- create new file - include ../view/header.php - include ../view/footer.php - use $categories from index.php, display - use $category_name and $products from index.php, display, create delete buttons, using post action - create add product link, using get action |
|
step 3 expand MVC, add program functions to delete products step 3 update Controller (mvC)= receive user request |
||
product_manager/index.php |
- update - handle delete if action is delete_product - use function "delete_product()" to be created in model/product_db.php below |
video 11_047 xampp eg010, 5, delete |
step 3 update Model (Mvc)= represent the data | ||
model/product_db.php |
- update - add function "delete_product()" to delete |
|
step 4 expand MVC, add program functions to show add product form step 4 update Controller (mvC)= receive user request |
||
product_manager/index.php |
- update - handle add if action is show_add_form - use function "get_categories()" which has been create in step 2 in model/category_db.php - include file product_add.php |
video 11_048 xampp eg010, 6, add product |
product_manager/ |
- create new file - handle add if action is show_add_form - include ../view/header.php - include ../view/footer.php - use $categories from index.php, display - capture user input, submit to index.php, action is add_product as hidden field - add link to index.php, action is list_products |
|
step 5 expand MVC, add program functions to add product step 5 update Controller (mvC)= receive user request |
||
product_manager/index.php |
- update - handle add if action is add_product - check empty field, if yes, include file ../errors/error.php - else, use "add_product()" function in model/product_db.php - send it back to self, keep $category_id |
|
step 5 create View (mVc)= user interface | ||
errors/ |
- create file, error.php - include ../view/header.php - include ../view/footer.php - show $error from index.php |
|
step 5 update Model (Mvc)= represent the data | ||
model/product_db.php |
- update - add function "add_product()" to add to database |
AJAX = Asynchronous JavaScript and XML
Files / Title | Description | Video |
---|---|---|
One way of creating XMLHttpRequest object from w3schools | ||
eg001.htm | - create XMLHttpRequest object, async=false, not recommenderead, read data from text file eg001_info.txt | |
eg002.htm | - create XMLHttpRequest object, async=true, the correct way, read data from text file eg001_info.txt |
|
Another way of creating XMLHttpRequest object from tizag.com | ||
eg003.htm | - create XMLHttpRequest object, onkeypress event, read data from php file eg003_time.php (txt file) | video 11_050 xampp ajax 1 video 11_051 xampp ajax 2 |
eg004.htm | - create XMLHttpRequest object, get data from database, using php file eg008c_select_changed.php (txt file), - two more files are needed eg008a_connect_database.php (txt file), and eg008b_database_error.php (txt file). |
video 11_052 xampp ajax 3 |
eg005.htm | - create XMLHttpRequest object, search data in database, using php file eg008c_select_search.php (txt file), - two more files are needed eg008a_connect_database.php (txt file), and eg008b_database_error.php (txt file). |
video 11_053 xampp ajax 4 |
eg006.htm | - search data in database, update one form field, using php file eg008c_select_single.php (txt file), - two more files are needed eg008a_connect_database.php (txt file), and eg008b_database_error.php (txt file). |
video 11_054 xampp ajax 5 |
Some other examples, including mail and dynamic textbox examples.
Files / Title | Description | Video |
---|---|---|
Simple mail example | ||
eg100_mail.php |
- simple mail example (works on most hosting service), it does not work with localhost unless you reconfig or install PEAR mail. | |
Use JavaScript to dynamically create textboxes | ||
- use JavaScript to dynamically create textboxes, and use another php file eg101_dynamic_process.php (text file) to pick up input. | ||
use php to dynamically create textboxes | ||
- to choose the number of textboxes... | video 11_055 xampp dynamic textbox 1 | |
eg102_dynamic_textbox.php |
- use php to dynamically create textboxes, and use another php file eg101_dynamic_process.php (text file) to pick up input (same as above). | video 11_056 xampp dynamic textbox 2
|
Upload file | ||
eg051.php |
- upload file | |
eg051_upload.php |
- need to create sub_folder "upload_folder" to save files | |
Scan files in a folder | ||
- scan all files in a folder - need to create sub_folder "eg052_dir" to store files inside |
||
Read the content of a text file | ||
- need to create sub_folder "eg053_dir" to store file inside | ||
Use Session to check login | ||
eg030_session_1.php eg030_session_2.php |
- create session variable
- retrieve session variable |
|
eg032_login.php eg032_logout.php eg032_main_content.php |
- user login, use session variable to check if login is successful - the content file will block user access if unauthorized access is detected |
|
Regular Expressions | ||
- use regular expressions to extract content (deliminators) | ||