PHP Programming Session 2 INFM 718N Web-Enabled Databases.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

10 Software Engineering Foundations of Computer Science ã Cengage Learning.
PHP Week 11 INFM 603. Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not.
Software Engineering and Design Principles Chapter 1.
Chapter 10.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Web Infrastructure Week 3 INFM 603. The Key Ideas Questions Structured Programming Modular Programming Data Structures Object-Oriented Programming.
Debugging and Ajax Session 7 INFM 718N Web-Enabled Databases.
Program Design and Development
Database Design and MySQL
Structured Programming and UML Overview Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
MySQL and PHP Integration Session 6 INFM 718N Web-Enabled Databases.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Modular Programming and Use Case Models Session 3 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Week 1 INFM 718N Web-Enabled Databases The Big Picture.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
PHP Programming Part II and Database Design Session 3 INFM 718N Web-Enabled Databases.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
C++ fundamentals.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Data Structures Session 8 LBSC 790 / INFM 718B Building the Human-Computer Interface.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
1 Shawlands Academy Higher Computing Software Development Unit.
Introduction to Shell Script Programming
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
CIS 199 Test 01 Review. Computer Hardware  Central Processing Unit (CPU)  Brains  Operations performed here  Main Memory (RAM)  Scratchpad  Work.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP Week 8 INFM 603. Agenda Questions PHP Drupal Project Plan.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
The Software Development Process
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
Python Let’s get started!.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Structured Programming and UML Introduction Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
PHP using MySQL Database for Web Development (part II)
Testing and Debugging.
Designing and Debugging Batch and Interactive COBOL Programs
PHP.
An Introduction to Debugging
Presentation transcript:

PHP Programming Session 2 INFM 718N Web-Enabled Databases

Agenda Programming PHP Idea Rally (40 minutes) Programming well

Database Server-side Programming Interchange Language Client-side Programming Web Browser Client Hardware Server Hardware (PC, Unix) (MySQL) (PHP) (HTML, XML) (JavaScript) (IE, Firefox) (PC) Business rules Interaction Design Interface Design Relational normalization Structured programming Software patterns Object-oriented design Functional decomposition

Software Software represents an aspect of reality –Input and output represent the state of the world –Software describes how the two are related Programming languages specify the model –Data structures model things –Structured programming models actions –Object-oriented programming links the two A development process organizes the effort

The Big Picture ??

Language Learning Learn some words Put those words together in simple ways Examine to broaden your understanding Create to deepen your mastery Repeat until fluent

Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging Procedural perspective (vs. object-oriented)

Making PHP HTML stuff <?php PHP stuff ?> HTML stuff stuff---/xxxxx.php

Variables Name starts with a $ –Case sensitive (assume everything could be!) Hold a value –Number (integer, float) –String (double quotes, \ escape character) –TRUE, FLASE –NULL Need not be declared, automatically cast

Operators in PHP Arithmetic operators + - * / Logical operators = > && || ! String operator.

Statements in PHP Sequential {…; …;…;} Semicolons are required at the end of every statement Conditional if (3==i) {…} else {…} Loop foreach ($array as $key => $value) {…} while ($row=mysql_fetch_array(…)) {…} For ($i=0; $i<10; $i++) {…} Braces are optional around a single statement

Arrays in PHP A set of key-element pairs $days = array(“Jan”->31, “Feb”=>28, …); $months = explode(“/”, “Jan/Feb/Mar/…/Dec”); $_POST Each element is accessed by the key –{$days[“Jan”]} –$months[0]; Arrays and loops work naturally together

Thinking about Arrays Naturally encodes an order among elements –$days = rksort($days); Natural data structure to use with a loop –Do the same thing to different data PHP unifies arrays and hashtables –Elements may be different types

Functions in PHP Declaration function multiply($a, $b=3){return $a*$b;} Invoking a method $b = multiply($b, 7); All variables in a function have only local scope Unless declared as global in the function

Why Modularity? Limit complexity –Extent –Interaction –Abstraction Minimize duplication

Using PHP with (X)HTML Forms ”, size=30 /> Yes No if (isset($_POST[“submitted”])) { echo “Your address is $ .”; } else { echo “Error: page reached without proper form submission!”; }

Sources of Complexity Syntax –Learn to read past the syntax to see the ideas –Copy working examples to get the same effect Interaction of data and control structures –Structured programming Modularity

Some Things to Pay Attention To Syntax How layout helps reading How variables are named How strings are used How input is obtained How output is created Structured Programming How things are nested How arrays are used Modular Programming Functional decomposition How functions are invoked How arguments work How scope is managed How errors are handled How results are passed

The “Idea Rally” A 90-second “elevator pitch” –One interesting and feasible idea –Plus why they should want you on their team! –Showing one optional powerpoint slide Illustrate your point, don’t say the same words! One-page handout (22 copies) –Your idea in a short paragraph –Your name, picture and contact information –A list of your strengths

First Things First Functionality Content Usability Security/Stability

What are Requirements? Attributes –Appearance –Concepts (represented by data) Behavior –What it does –How you control it –How you observe the results

Who Sets the Requirements? People who need the task done (customers) People that will operate the system (users) People who use the system’s outputs People who provide the system’s inputs Whoever pays for it (requirements commissioner)

The Requirements Interview Focus the discussion on the task –Look for entities that are mentioned Discuss the system’s most important effects –Displays, reports, data storage –Learn where the system’s inputs come from –People, stored data, devices, … Note any data that is mentioned –Try to understand the structure of the data Shoot for the big picture, not every detail

The Project Plan One-page contract –Between developer and requirements commissioner Goal The problem to be solved ProductWhat you plan to deliver ScopeAvailable time and personnel RolesWhat you expect each other to do

Programming Skills Hierarchy Reusing code [run the book’s programs] Understanding patterns [read the book] Applying patterns [modify programs] Coding without patterns [programming] Recognizing new patterns

Best Practices Design before you build Focus your learning Program defensively Limit complexity Debug syntax from the top down

Rapid Prototyping + Waterfall Update Requirements Choose Functionality Build Prototype Initial Requirements Write Specification Create Software Write Test Plan

Focus Your Learning Find examples that work –Tutorials, articles, examples Cut them down to focus on what you need –Easiest to learn with throwaway programs Once it works, include it in your program –If it fails, you have a working example to look at

Defensive Programming Goal of software is to create desired output Programs transform input into output –Some inputs may yield undesired output Methods should enforce input assumptions –Guards against the user and the programmer! Everything should be done inside methods

Limiting Complexity Single errors are usually easy to fix –So avoid introducing multiple errors Start with something that works –Start with an existing program if possible –If starting from scratch, start small Add one new feature –Preferably isolated in its own method

Types of Errors Syntax errors –Detected at compile time Run time exceptions –Cause system-detected failures at run time Logic errors –Cause unanticipated behavior (detected by you!) Design errors –Fail to meet the need (detected by stakeholders)

Debugging Syntax Errors Focus on the first error message –Fix one thing at a time The line number is where it was detected –It may have been caused much earlier Understand the cause of “warnings” –They may give a clue about later errors If all else fails, comment out large code regions –If it compiles, the error is in the commented part

Run Time Exceptions Occur when you try to do the impossible –Use a null variable, divide by zero, … The cause is almost never where the error is –Why is the variable null? Exceptions often indicate a logic error –Find why it happened, not just a quick fix!

Debugging Run-Time Exceptions Run the program to get a stack trace –Where was this function called from? Print variable values before the failure Reason backwards to find the cause –Why do they have these values? If necessary, print some values further back

Logic Errors Evidenced by inappropriate behavior Can’t be automatically detected –“Inappropriate” is subjective Sometimes very hard to detect –Sometimes dependent on user behavior –Sometimes (apparently) random Cause can be hard to pin down

Debugging Logic Errors First, look where the bad data was created If that fails, print variables at key locations –if (DEBUG) echo “\$foobar = $foobar”; Examine output for unexpected patterns Once found, proceed as for run time errors –define (“DEBUG”, FALSE); to clean the output

Three Big Ideas Functional decomposition –Outside-in design High-level languages –Structured programming, object-oriented design Patterns –Design patterns, standard algorithms, code reuse

One-Minute Paper What was the muddiest point in today’s class? Be brief! No names!