Week FourWeek Four
CIT 354 Internet IICIT 354 Internet II
22
ObjectivesObjectives
Uploading Files to Your Web SiteUploading Files to Your Web Site
Establishing a ConnectionEstablishing a Connection
Creating a Database TableCreating a Database Table
Common Programming ErrorsCommon Programming Errors
SummarySummary
Mid-term, Homework, and ProjectMid-term, Homework, and Project
33
Uploading Files to Your Web SiteUploading Files to Your Web Site
Check Your php.ini File Check Your php.ini File
Understanding the ProcessUnderstanding the Process
Creating the FormCreating the Form
Creating the Upload ScriptCreating the Upload Script
Uploading a File Using Your Form and ScriptUploading a File Using Your Form and Script
44
Check Your php.ini FileCheck Your php.ini File
Uncomment the upload_tmp_dirUncomment the upload_tmp_dir
A directory name = /My Documents/tempA directory name = /My Documents/temp
55
Understanding the ProcessUnderstanding the Process
Creating the FormCreating the Form– upload_form.html (P 170)upload_form.html (P 170)
Creating the Upload ScriptCreating the Upload Script– do_upload.php (P 173)do_upload.php (P 173)– modify the path namemodify the path name
//Program Files/ApacheProgram Files/Apache Group/Apache/htdocs/Group/Apache/htdocs/
Submitting your Form and Getting Submitting your Form and Getting ResultsResults
66
Establishing a ConnectionEstablishing a Connection
Connect to MySqlConnect to MySql
List all databases on localhostList all databases on localhost
List all tables in a databaseList all tables in a database
Create a databaseCreate a database
Drop (delete) a databaseDrop (delete) a database
77
Working with User Privileges in MySqlWorking with User Privileges in MySql
Creating a New UserCreating a New User– GRANT [privilege list] ON databasename.tablename GRANT [privilege list] ON databasename.tablename
TO TO username@hostusername@host IDENTIFIED BY “password” IDENTIFIED BY “password”– cd c:\mysql\bin and issue mysql cd c:\mysql\bin and issue mysql – use mysql;use mysql;
Connecting to MySqlConnecting to MySql– Command: mysqlconnectCommand: mysqlconnect– Example: db_connect.php (P181)Example: db_connect.php (P181)
Breaking Your Connection ScriptBreaking Your Connection Script– Example: db_connect.php (P183)Example: db_connect.php (P183)
88
List all databases on localhostList all databases on localhost
Listing Databases on a ServerListing Databases on a Server
Commands:Commands:– mysql_list_dbs()mysql_list_dbs()– mysql_num_rows()mysql_num_rows()– mysql_tablename()mysql_tablename()
Example: db_listdb.php (P 186)Example: db_listdb.php (P 186)
99
List all tables in a databaseList all tables in a database
Command: mysql_list_tables()Command: mysql_list_tables()
Example: db_listtablesdb.php (P 188)Example: db_listtablesdb.php (P 188)
1010
Create a New databaseCreate a New database
Command: $new_dbCommand: $new_db
Example: db_createdb.php (P 193)Example: db_createdb.php (P 193)
TestsTests– Re-start Apache and then run db_listdb.phpRe-start Apache and then run db_listdb.php– Restart mysqlRestart mysql
1111
Drop (delete) a databaseDrop (delete) a database
Command: $drop_dbCommand: $drop_db
Example: db_dropdb.php (P 196)Example: db_dropdb.php (P 196)
1212
Creating a Database tableCreating a Database table
Plan for a database tablePlan for a database table
Recognize the pitfalls of certain data Recognize the pitfalls of certain data typestypes
Recognize the importance of unique Recognize the importance of unique fieldsfields
Follow a three-step process for table Follow a three-step process for table creationcreation
Create a table to hold your personal Create a table to hold your personal music catalogmusic catalog
1313
Planning for Your TablesPlanning for Your TablesBasic MySQL Data TypesBasic MySQL Data Types– Table 12.1 Some MySQL Data TypesTable 12.1 Some MySQL Data Types– Examples: TINYINT (1 byte), SMALLINT (2 bytes), Examples: TINYINT (1 byte), SMALLINT (2 bytes),
MEDIUMINT(3 bytes), INT (4 BYTES), BIGINT(8 MEDIUMINT(3 bytes), INT (4 BYTES), BIGINT(8 bytes), FLOAT(M,D), DATE(YYYY-MM-DD)bytes), FLOAT(M,D), DATE(YYYY-MM-DD)
Defining Your FieldsDefining Your Fields– Define fields correctlyDefine fields correctly– Define fields with the right SQL syntaxDefine fields with the right SQL syntax– Steps:Steps:
1. The name of the table and number of fields1. The name of the table and number of fields
2. Display additional form fields2. Display additional form fields
3. Verification3. Verification
1414
Planning for Your TablesPlanning for Your Tables
Table 12.2 Fields for my_musicTable 12.2 Fields for my_musicThe importance of Unique FieldsThe importance of Unique Fields– An ID Field can be used as the unique field An ID Field can be used as the unique field
A Three-Step Form SequenceA Three-Step Form SequenceStep 1: Number of FieldsStep 1: Number of FieldsExample: show_createtable.html (P 203)Example: show_createtable.html (P 203)Step 2: Defining Your FieldsStep 2: Defining Your FieldsExample: do_showfielddef.php (P 205)Example: do_showfielddef.php (P 205)Step 3: Creating the TableStep 3: Creating the TableExample: do_createtable.php (P 212)Example: do_createtable.php (P 212)
Use your own ID and PW to connect MySQl.Use your own ID and PW to connect MySQl.
1515
Common Programming ErrorsCommon Programming ErrorsOmitting or incorrectly typing the opening tag <? that Omitting or incorrectly typing the opening tag <? that signifies the start of a PHP statement.signifies the start of a PHP statement.Omitting or incorrectly typing the closing tag ?> that Omitting or incorrectly typing the closing tag ?> that signifies the end of a PHP statement.signifies the end of a PHP statement.Misspelling the name of a variable or function.Misspelling the name of a variable or function.Forgetting to close a string with a double quote symbol.Forgetting to close a string with a double quote symbol.Dividing integer values incorrectly.Dividing integer values incorrectly.Forgot to use the escape (\) character.Forgot to use the escape (\) character.Using a variable in an expression before a value has Using a variable in an expression before a value has been assigned to the variable.been assigned to the variable.Incorrectly typing the letter O for the number zero (0), or Incorrectly typing the letter O for the number zero (0), or vice versa. Incorrectly typing the letter l, for the number vice versa. Incorrectly typing the letter l, for the number 1, or vice versa.1, or vice versa.
1616
Chapter SummaryChapter Summary
Uploading Files to Your Web SiteUploading Files to Your Web Site
Establishing a ConnectionEstablishing a Connection
Creating a Database TableCreating a Database Table
1717
Mid-term, Homework, and ProjectMid-term, Homework, and Project
Mid-termMid-term– Date: Next WeekDate: Next Week
Homework 3Homework 3– Due Date: Next WeekDue Date: Next Week
Project 1Project 1– Due Date: Next WeekDue Date: Next Week– Team Approach( 1 – 3 members)Team Approach( 1 – 3 members)