Richard's PHP Page :: 2012


Useful Links

Useful Links for Installation


This page contains stuff from the murach's PHP and MySQL book.

Is PHP case sensitive???

PHP variable names are case sensitive, but the names of functions are NOT case sensitive. To expand on this...

Case sensitive
:: variables / constants
:: class properties / constants
:: array
:: class constants

NOT case sensitive
:: functions
:: class constructors / methods
:: keywords and constructs (if, else, etc.)

Espression Web 4 Quick Tips

1.1. Panels > Workspaces > Designer OR Panels > Reset Workspace Layout
1.2. View > Toolbars
1.3. View > Custom Toolbars (may not be applicable)
1.4. Snapshot is only for preview, not for testing interactivity
1.5. Panels > .... (play with it)

2.1. Site > New Site > Empty Web Site > .... enter new folder name
2.2. Tools > Page Editor Options > Authoring Tab > HTML 5 (for both); css3 draft; turn OFF (BOM)

3.1. File > New > Page > HTML
3.2. Design / Split / Code (below screen)
3.3. File > Save (or Save icon)
3.4. Tools > Page Editor Options > Default Font > Code View > 16

4.1. File > New > Page > CSS
4.2. Save icon (or right-click tab to save)
4.3. Folder list, drag *.css file to the *.htm file on the main panel, save *.htm file

5.1. Lower-right hand corner (CSS Mode), Mode > Manual

1 :: YouTube video (external site) - Expression Web 4 - Step 1: Set up Empty Web Site
2 :: YouTube video (external site) - Expression Web 4 - Step 2: Set the Doctype
3 :: YouTube video (external site) - Expression Web 4 - Step 3: Make a Blank Web Page
4 :: YouTube video (external site) - Expression Web 4 - Step 4: Make an External Style Sheet
5 :: YouTube video (external site) - Expression Web 4 - Step 5- Style application Mode


Basic PHP

1. eg001_basic.php (text file) - comments, php tag in html, decleration of variables

2. eg002_basic.php (text file) - variables, data types, loops etc

3. eg003_input.php (text file) - get user input, submit form to eg003_process.php (text file), and something interesting, a loan calculator from external site (in js)

4. eg004_function.php (text file) - function

5. eg005_array.php (text file) - array and associative array

6. eg041.php (text file) - get user input, submit form to eg041action.php (text file)
:: eg060.php (text file) - connect to a local MySQL database

 

7.
eg007 shows the "old" PHP 4 way of dealing with database, it also works until PHP 5.4, it should NOT work (on and) after PHP 5.5.
:: if you use MS Expression Web or Adobe Dreamweaver, create a new site eg007
7.1
Start mysql service; start apache web server
Login as root (go to cmd)
mysql -u root -p (rootpass is follow mysql installation)
mysql> GRANT ALL PRIVILEGES ON *.* TO harry@localhost IDENTIFIED BY 'elbomonkey' WITH GRANT OPTION;
mysql>show databases;
mysql>create database sample;
mysql>show databases;
if needed, adjust privileges in phpMyAdmin (http://localhost:8080/phpMyAdmin/index.php); Privileges tab; Edit Privileges; uncheck all Structure and Administration, click GO
:: eg007a_connect.php (text file) - connect to a local database

7.2
mysql> use sample
mysql>
create table domains (id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
domain VARCHAR (20),
sex CHAR (1),
mail VARCHAR (20));
:: eg007b_insert.php (text file) - insert statement
:: eg007c_select.php (text file) - select statement
:: eg007d_form.php (text file) - insert statement through a form, processed by eg007d_process.php (text file)
:: eg007e_update.php (text file) - update a record in database using <option> tag in form
:: eg007f_connect_open.php (text file) - open database connection; eg007f_connect_close.php (text file) - close database connection
:: eg007f_edit.php (text file) -> eg007f_edit_form.php (text file) -> eg007f_edit_data.php (text file) -> eg007f_delete.php (text file)

 

8.
eg008 show the PHP 5 (and later) way of dealing with database, it does not work with earlier PHP versions. PDO (PHP Data Objects) is included with PHP 5.1. PDO defines a consistent interface for accessing databases.
:: phpMyAdmin > Import > File to Import > Browse > create_db.sql (download from D2L)
:: eg008a_connect_database.php (text file)
:: eg008b_database_error.php (text file)
:: eg008c_select.php (text file) - select statement
:: eg008d_insert.php (text file) - insert statement
:: eg008e_update.php (text file) - delete statement
:: eg008f_delete.php (text file) - update statement

Syntax summary:
new ClassName(arguments); //create an object from class

new PDO($dsn, $username, $password); //create database object from PDO class

mysql:host=host_address;dbname=database_name //DSN for MySQL

try {
} catch (ExceptionClass $exception_name) {
}

 

9.
eg009 is from the murach's PHP and MySQL book, Ch 4 - product manager application.
:: create a new folder eg009
:: if you use MS Expression Web or Adobe Dreamweaver, create a new site(folder) eg009
:: downloand main.css from D2L, put in the folder

9.1 create database "my_guitar_shop_1" and create user "mgs_user" and "mgs_tester" with limited privileges.
:: phpMyAdmin > Import > File to Import > Browse > my_guitar_shop1.sql (download from D2L)
:: note that this SQL example did not use foreign key "REFERENCES" to simply php learning. In real application development foreign key referencing is important. If foreign key referencing is used, you can use MySQL Workbench to check E-R diagram (not necessary for PHP learning).
:: check resulting tables in phpMyAdmin
:: if you want to create local and global privileges, use two sql statements

9.2 create files to connect to database
:: eg009a_connect_database.php (text file)
:: eg009b_database_error.php (text file)

9.3 create the index page (this should be the home page, index.php in an web application)
:: eg009c_index.php (text file)

9.4 create page to delete product
:: eg009d_delete_product.php (text file)

9.5 create page to add product
:: eg009e_add_product_form.php (text file)
:: eg009f_add_product.php (text file)
:: eg009g_error.php (text file)

 

30
eg030_session_1.php (text file) starts a session, save session variables; and redirects to eg031_session_2.php (text file), which retrieves session variables

eg031_index.php (text file), php only, starts a session, create a global variable array), and decide on things (which action to take, which file to include etc)
eg031_cart.php (text file), php only, store all the functions, like a library
eg031_add_item_view.php (text file), html and php, show add item menu, store value to session variables
eg031_cart_view.php (text file), html and php, who items in shopping cart, load session variables



Something Else

100. eg100_mail.php (eg100_mail.txt), simple mail example (works on most hosting service), it does not work with localhost unless you reconfig or install PEAR mail.

101. eg101_dynamic_textbox.php (text file) - use JavaScript to dynamically create textboxes, and use another php file eg101_dynamic_process.php (text file) to pick up input.

102 eg102_choice.htm - to choose the number of textboxes...
eg102_dynamic_textbox.php (text file) - use php to dynamically create textboxes, and use another php file eg101_dynamic_process.php (text file) to pick up input (same as above).

 

A little bit of AJAX

Richard's AJAX page