Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy
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
Tools Filezilla (FTP) (client download) Filezilla (FTP) (client download) PHP Programming PHP Programming
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.
Using mySCC Use your desktop credentials
Using mySCC CIS-BPC folder contains the Eclipse and Filezilla applications. My_Documents contains the contents of the student H: drive.
IMPORTANT NOTE All filenames lower case alphanumeric names.
Eclipse
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.
PHP Syntax “Hello” “Hello” ‘Hello’ ‘Hello’ ; { } { } print( ) print( ) \.
PHP <html><body><?php print(“ This is text. \n”); ?></body></html>
IMPORTANT NOTE PHP files must have the extension.php and be uploaded to a web server capable of serving up PHP files.
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”);
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 “.
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.
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
If …Then Statements $d=“Rob”; if ($d==“Rob”) { print("Hello! \n)"; } else { print(“Goodbye! \n)"; }
Switch/Case Statements $d=“Rob”; switch ($d) { case “Rob”: print(“ Hello Cuz! \n)"; break; case “Tom”: case “Tom”: print(“ \n)"; break; default: print(“ Hello Who? \n)"; }
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.
For … Next Statements for ($i=1; $i I equals: ".$i." \n“); }
Do … While Statements $i=1; while($i Number is ".$i. " \n“); $i++; }
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”];
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”];
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”);
In-class Calculator
HTML Calculator Lessons: 1.print 2.$_POST 3.if … then 4.switch/case
PHP Operators - Math + - Addition + - Addition - - Subtraction - - Subtraction * - Multiplication * - Multiplication / - Division / - Division % - Modulus (division remainder) % - Modulus (division remainder)
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
HTML Forms Name: Name: Greeting: Greeting: </p></form>
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)
Form data and PHP 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”);
Updating HTML using PHP ” /> ” /> 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 (\).
Questions?
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 to Rob Loy with URL to homework1a.php before 6pm on September 21. Send to Rob Loy with URL to homework1a.php before 6pm on September 21.
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 to Rob Loy with URL to calculator file before 6pm on September 21. Send to Rob Loy with URL to calculator file before 6pm on September 21.