380 likes | 540 Views
CIS166AE : PHP Web Scripting. Rob Loy. Tonight’s Agenda. Housekeeping items PHP basics Student connection to server In-class work. Class Logistics. Dates: Sept 5 to Dec 12 Time: Wednesday 6:00 - 9:50pm (Lab time included in class time) Room: CM 447 Section: 36721. Class Structure.
E N D
CIS166AE : PHP Web Scripting Rob Loy
Tonight’s Agenda • Housekeeping items • PHP basics • Student connection to server • In-class work
Class Logistics • Dates: Sept 5 to Dec 12 • Time: Wednesday 6:00 - 9:50pm(Lab time included in class time) • Room: CM 447 • Section: 36721
Class Structure • Review of homework and lab • Any quizzes or presentations • Lecture/new materials • In-class (hands on) work • Lab work
Class Contact • Web Content: http://www.robloy.com/php • Email1: rob.loy@scc.maricopa.edu • Email2: rob.loy@gmail.com • Phone: 602-418-4041 Send email to BOTH emails for faster response
Class Tools • Eclipse with PHP • Filezilla • Internet Explorer • Phpmyadmin (SQL) • mySCC • SCC Class Folders “CIS-166/”
Student Expectations • Understand basic HTML • Do not need to know programming logic • All assignments will be attempted even if not completed to get a “C” • Some assignments will require work OUTSIDE the class room
Expected Knowledge • Basic HTML Code • Right+click menus • Shortcuts (Copy/Paste etc.) • Folder structures
Class Standards • Lower-case, alphanumeric filenames • Homework submitted by 6:00pm next class • All links emailed to working page on the site • New folder created each week • Lab time is optional, but lab assignment MUST be completed
Semester Agenda • PHP Basics • PHP Functions • PHP Object Orientated Programming (OOP) • PHP/mySQL Databases • PHP Module Creation • PHP Applications
Open Source Environment • L INUX: Operating system for server • A pache: Web server for server • M ySQL: DB application for server • P HP: programming language • XXAMP: Windows complete Apache, PHP and mySQL environment
PHP Environment • Filename extensions has to be .php • Requests from the user goes to an Apache Web Server • Server processes all programming and returns HTML to client (browser) • Any storage is usually in a database on the server side
PHP Basics • Environment • Variable • Constants • Arrays • Code branching • Loops
PHP Functions • PHP Built-in functions • User created functions • Parameters • Scope
PHP OOP • Object Oriented Programming (OOP) • Class creation • Object creation • OOP Methods
PHP/mySQL DB • Databases 101 • phpmyadmin • SQL SELECT • SQL INSERT • SQL UPDATE
User Created Modules • Web contact page • Newsletter sign-up • Secured pages • Image gallery • Facebook application • Mobile application (web service)
PHP Applications • WordPress • OSCommerce • Drupal • Any other PHP applications?
Student Connection • Domain: http://<domainname>.com • FTP URL: <domainname>.com • Username: springscc<number> • Password: <given in class> • Directory: <domainname> • mySQL Admin: mysql.<domainname>.com
PHP Coding Terms • Whitespace does not impact results • { } = braces / curlies • () = parenthesis • ; = semicolon • \ = back slash • / = forward clash
PHP Operators - Math • + - Addition • - - Subtraction • * - Multiplication • / - Division • % - Modulus (division remainder) • ++ - Incement + 1 • -- - Decrement – 1 • . - String addition (e.g 1.1 = 11) http://www.w3schools/php/php_operators.asp
PHP Operators - Comparison • < - Less than • > - Greater than • <> - Not equal • == - Equals • ! - NOT (e.g. !== means NOT equal) http://www.w3schools/php/php_operators.asp
Basic PHP Code Syntax • <?php ?>: contains PHP code for the server to translate • //: php comments • echo $a;: prints the item or variable to the screen • print($a);: prints the item or variable to the screen • All statements end with a semicolon
PHP Variables • Variables are represented by a dollar sign followed by the name of the variable. • Not tied to a specific type of variable like Java, .NET. • A variable name can only contain alpha-numeric characters and underscores • Variable name is case-sensitive. • Examples: $cost, $obj_name • Syntax: $cost = 4.12, $obj_name = “bike” http://www.w3schools/php/php_variables.asp
PHP Arrays • Variable capable of holding more than one value in a single reference variable • Content held in a Key / Value config • Examples: $month[] • Syntax set-up: $month = array(“Jan”,”Feb”,“Mar”,“Apr”); • Syntax look-up:echo $month[2]; $month = array(“Jan”,”Feb”,“Mar”,“Apr”); http://php.net/manual/en/language.types.array.php
PHP Constants • A constant cannot change value • A constant is case-sensitive by default • Constant identifiers are uppercase • Examples: COST, UNIT_TAX • Syntax: DEFINE (COST, 4.12)DEFINE (OBJ_NAME, “My bicycle”); http://php.net/manual/en/language.constants.php
PHP & HTML (1) <?php $a = “John”; ?> <html> <body> <p>Hello <?php echo $john; ?></p> </body> </html>
PHP & HTML (2) <?php $a = “John”; echo “<html>\n”; echo “<body> echo “<p>Hello “ . $john . “</p>\n”; echo “</body>\n”; echo “</html>\n”; ?>
IMPORTANT NOTE • Eclipse is part of MySCC • Filezilla is part of MySCC • You can NOT use MySCC Filezilla in class • For each class, download Filezilla and install on the desktop!
FTP (Filezilla) • Connect to remote server using credentials • Click files and then click: • GET file FROM remote server • PUT files ON to remote server • Drag files to move files • Can also RIGHT CLICK to see more options
Editing (Notepad) • Open Notepad • Save file as index.php • You can use any text editor
HTML Form Syntax • Form method: How the information goes. • GET = in the URL string • POST = in HTTP Header (preferred) • Form action: Where the information goes. • Input name: How the information is stored (“variable” name)
PHP & HTML Forms <form method=“POST” action=“form.php”> <input type=“text” name=“fred”> <input type=“submit”> </form> form.html <?php echo “<p>Name is “.$_POST[“fred”].“</p>\n”; ?> form.php
Previewing Work • Use any browser • Navigate to the URL and the folder/file name(reminder case-sensitive) • Might have to click F5 to refresh pages • Check HTML -> View Source
Next Week • Programming basic • User Functions • PHP Functions • Eclipse (IDE)
Homework/Lab • 1) Send me an email with your domain name you picked in class • 2) Send me an email with the link to the work we did in class in a folder called “homework1”. The homework should be accessible at the following URL: http://<domainname>.com/homework1/index.php