Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.

Similar presentations


Presentation on theme: "Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy."— Presentation transcript:

1 Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy

2 Agenda Review homework & lab Review homework & lab Tools (Eclipse) Tools (Eclipse) PHP branching PHP branching PHP looping PHP looping In-class calculator In-class calculator Lab Lab

3 Tools Filezilla (FTP) http://filezilla-project.org (client download) Filezilla (FTP) http://filezilla-project.org (client download) PHP Programming http://www.eclipse.org/pdt/downloads/ PHP Programming http://www.eclipse.org/pdt/downloads/

4 IMPORANT DEFINITIONS Client –Computer that uses the services of another computer. A browser is an example of a client program. Client –Computer that uses the services of another computer. A browser is an example of a client program. Server –Computer program that delivers (serves) content over the World Wide Web. Server –Computer program that delivers (serves) content over the World Wide Web.

5 Using mySCC Use your desktop credentials

6 Using mySCC CIS-BPC folder contains the Eclipse and Filezilla applications. My_Documents contains the contents of the student H: drive.

7 IMPORTANT NOTE All filenames lower case alphanumeric names.

8 Eclipse

9 Syntax Validation in Eclipse Red “squiggly” lines indicate an expected syntax error. Although not all syntax errors are caught. Notice missing closing “ but no syntax errors shown.

10 PHP Syntax “Hello” “Hello” ‘Hello’ ‘Hello’ ; { } { } print( ) print( ) \. http://www.w3schools.com/php/php_syntax.asp

11 PHP <html><body><?php print(“ This is text. \n”); ?></body></html>

12 IMPORTANT NOTE PHP files must have the extension.php and be uploaded to a web server capable of serving up PHP files.

13 PHP and HTML HTML can be included within PHP text /strings. HTML can be included within PHP text /strings. To format the VIEW SOURCE, add the \n for line breaks. This has no impact on the user experience. To format the VIEW SOURCE, add the \n for line breaks. This has no impact on the user experience. print(“ This is text. \n”); http://www.w3schools.com/php/php_variables.asp

14 PHP Variables and HTML $a = “Rob”; print(“ Hello “.$a.”. \n”); You can add variables to text by concatenating the string with “.”. You can add variables to text by concatenating the string with “.”. First exit the string using a “ then add the variable then return to the string using another “. First exit the string using a “ then add the variable then return to the string using another “. http://www.w3schools.com/php/php_variables.asp

15 IMPORTANT NOTE x = y does not compare x to y but instead sets y equal to x. Instead use x==y for comparison. x = y does not compare x to y but instead sets y equal to x. Instead use x==y for comparison.

16 Logic Structures Conditional Conditional if … then … elseif if … then … elseif switch/case statements switch/case statements Loops Loops for … next for … next do … while do … while

17 If …Then Statements $d=“Rob”; if ($d==“Rob”) { print("Hello! \n)"; } else { print(“Goodbye! \n)"; } http://www.w3schools.com/php/php_if_else.asp

18 Switch/Case Statements http://www.w3schools.com/php/php_switch.asp $d=“Rob”; switch ($d) { case “Rob”: print(“ Hello Cuz! \n)"; break; case “Tom”: case “Tom”: print(“ \n)"; break; default: print(“ Hello Who? \n)"; }

19 IMPORTANT NOTE For LOOPS, must have an achievable test case to avoid endless loops. Need to know the test scenario. For LOOPS, must have an achievable test case to avoid endless loops. Need to know the test scenario.

20 For … Next Statements for ($i=1; $i I equals: ".$i." \n“); } http://www.w3schools.com/php/php_looping_for.asp

21 Do … While Statements http://www.w3schools.com/php/php_looping.asp $i=1; while($i Number is ".$i. " \n“); $i++; }

22 HTML Drop-downs HTML drop-downs have names and values HTML drop-downs have names and values Orange Orange Red Red Black Black </select> To access the information you use the form “name” To access the information you use the form “name” $a = $_POST[“mylist”];

23 HTML Radio Buttons Radio buttons only have values and names. Radio buttons only have values and names. If the names are the same, only ONE button can be selected at a time. If the names are the same, only ONE button can be selected at a time. + + - - To access the information you use the form “name” To access the information you use the form “name” $a = $_POST[“op”];

24 PHP Redirect To send the user to another page, you can redirect them… To send the user to another page, you can redirect them… header(“location:newpage.php”); header(“location:newpage.php”);

25 In-class Calculator

26 HTML Calculator Lessons: 1.print 2.$_POST 3.if … then 4.switch/case

27 PHP Operators - Math + - Addition + - Addition - - Subtraction - - Subtraction * - Multiplication * - Multiplication / - Division / - Division % - Modulus (division remainder) % - Modulus (division remainder) http://www.w3schools.com/php/php_operators.asp

28 Logic for calculator User inputs TWO numbers User inputs TWO numbers User selects the math function User selects the math function User clicks submit User clicks submit Depending on the function selected, process the TWO numbers Depending on the function selected, process the TWO numbers Display the result Display the result Send the user back to the initial screen Send the user back to the initial screen

29 HTML Forms http://www.w3schools.com/html/html_forms.asp Name: Name: Greeting: Greeting: </p></form>

30 HTML Form Syntax Form method: How the information goes. Form method: How the information goes. GET = in the URL string GET = in the URL string POST = in HTTP Header (preferred) POST = in HTTP Header (preferred) Form action: Where the information goes. Form action: Where the information goes. Input name: How the information is stored (“variable” name) Input name: How the information is stored (“variable” name)

31 Form data and PHP http://www.w3schools.com/php/php_post.asp Code to access in the information goes in the page named in the action. Code to access in the information goes in the page named in the action. input type="text" name=“name" /> To get the value entered, the method type and input name are used: To get the value entered, the method type and input name are used: print(“ Name was “. $_POST[“name”]. “ \n”);

32 Updating HTML using PHP http://www.w3schools.com/php/php_post.asp ” /> ” /> Short blocks of PHP can be inserted in to HTML. Short blocks of PHP can be inserted in to HTML. print(“ \n”); Entire HTML lines can be created within PHP by mixing “ and ‘ quote marks. Entire HTML lines can be created within PHP by mixing “ and ‘ quote marks. print(“ \n”); Entire HTML lines can be created within PHP by using literal markings (\). Entire HTML lines can be created within PHP by using literal markings (\).

33 Questions?

34 Lab Make an HTML page that the user inputs a number. Make an HTML page that the user inputs a number. When the user clicks submit the screen should display all the odd numbers between 0 and the number inputted. When the user clicks submit the screen should display all the odd numbers between 0 and the number inputted. Send email to Rob Loy with URL to homework1a.php before 6pm on September 21. Send email to Rob Loy with URL to homework1a.php before 6pm on September 21.

35 Homework Create a folder called homework2. Create a folder called homework2. Copy all the files for the calculator to that folder. Copy all the files for the calculator to that folder. Add to the class project to create functionality for MULTIPLICATION and DIVISION. Add to the class project to create functionality for MULTIPLICATION and DIVISION. Send email to Rob Loy with URL to calculator file before 6pm on September 21. Send email to Rob Loy with URL to calculator file before 6pm on September 21.


Download ppt "Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy."

Similar presentations


Ads by Google