September 25 - ndgriffeth/Class-Notes-and-Lectures GitHub Wiki
-
Reading: Chapters 2-3
-
Write, test, and turn in an html page with a form that asks for inputs of the types:
text box checkbox radio button
-
Write, test, and turn in a php script to use the values submitted by the above form. It should test whether they are blank and print either "no value" or the type and the value of each of the inputs.
-
(Preview) For October 2: Get together in a team of 2-3 people and decide on a PHP project that will require registration, logins, checkouts, and maintenance of data by the project.
Here's an example page:
What's needed?
- Form
- Input text for "Name"
- Input password for "Password"
- Input submit button
- Header, text, formatting
See if you can reproduce the page.
Here's what I did in the php script:
What's needed?
- Static content: just the HTML stuff
- Dynamic content: generated by an "echo" and the date() function
Functions
Operators
NOTE
PHP and HTML can be arbitrarily interleaved, as long as you surround the PHP its start and end delimiters (not exactly HTML tags).
Let's use the information the user provided:
What's needed?
Variables
- Variable scope
- Superglobals ($_SERVER, $_POST, $_GET, $_REQUEST)
- Types
- Type safety (none)
- Variable variables
Functions
NOTE
- It's very useful to be able to see what the computer/software is "seeing".
- The input type and the variable type are not the same thing. The input type designates the way the input is submitted (e.g., "text" means a text box). The variable type reflects the usage and content of a variable. However, inputs from text boxes are always strings.
- Strings can be used in arithmetic, where php does everything possible to interpret them as numbers.
Challenge questions
- What is the type of the variable if you type a number in a text box?
- How is a boolean value stored?
- What happens if you use a string in a computation?
Let's see if arithmetic is familiar.
What's needed
- Arithmetic operators
- Comparison operators (logical operators)
- Control structures (if/then, etc.)
-
What does the date_default_timezone_set function do?
-
What is the string produced on the output Web page by each of the following, if $name has the value "Joe".
a. echo '$name is '.$name.'<br />';
$name is Joe
b. echo "$name is ".$name."<br />";
Joe is Joe
c. echo "Name is $name<br />";
Name is Joe
d. echo "$name is $name<br />";
Joe is Joe
- Write php (and/or html) code corresponding to the form below, which returns a Web page containing one line for each input, with the input name (as displayed on the form) and the input value next to it.
<form action="action.php" method="post"> <table> <tr> <td><b>Name</b>:</td><td><input type="text" name="name"></td> </tr><tr> <td><b>Password</b>:</td><td><input type="password" name="password"></td> </tr> </table> </form>