Difference between revisions of "AIM Class8"

esse quam videri
Jump to: navigation, search
(Simple POST)
(PHP)
Line 24: Line 24:
 
==PHP==
 
==PHP==
  
TODO write something about php here....
+
 
 +
1.Backstory
 +
2.acronym
 +
3.structure
 +
4.open-source (and what that means)
 +
5.timeline: 1994, 1998 (3.0), 2000 (4) and 5
 +
6.server-side vs. client-side
 +
7.server-side processing
 +
8.delimiters
 +
9.functions
 +
10.parameters
 +
11.echo shortcut (<?=”output”;?>
 +
12.variables (& datatypes – strings, numeric, and boolean) ex: $variableName
 +
13.variable naming conventions (don'ts: starting with  _ or numbers)
 +
14.line termination (just like actionscript & javascript)
 +
15.quotes – double and single(#4)
 +
16.escape characters
 +
\n linefeed and \r carriage return
 +
\t horizontal tab
 +
\\ backslash
 +
\$ dollar sign
 +
\” double quote and \' single quote
 +
17.numeric values (example)
 +
18.concatenating multiple lines using .=
 +
19.conditional statements
 +
20.more functions(ucwords, strtoupper)
 +
21.custom functions
 +
Misc notes: editors to use, resources to explore, etc.
 +
 
 +
Code examples:
 +
<pre>
 +
one.php
 +
<?php
 +
phpinfo();
 +
?>
 +
 
 +
two.php
 +
<?php
 +
$variable1 = "value of variable 1";
 +
$variable2 = "value of variable 2 with $variable1 embedded";
 +
echo $variable2;
 +
?>
 +
three.php
 +
<?php
 +
$variable1 = "value of variable 1";
 +
$variable2 = "Value of variable 2 with $variable1 embedded";
 +
echo $variable2;
 +
echo "<br />Double quotes are strange because you can express the value of a variable by just referencing the variable name in a string, ";
 +
echo "<br />and single quotes can be confusing when concatenating variable values.";
 +
$variable3 = 'single quote variable 3';
 +
$variable4 = '<br />variable 4 with $variable3 referenced (but not displayed unless you concatenate it like so: '.$variable3.')';
 +
echo $variable4;
 +
?>
 +
 
 +
four.php
 +
<?php
 +
echo "To use a single quote in a double-quoted string is no problem, but it is in a single-quoted string.";
 +
echo "If you are using single quotes, you will need to escape the apostrophe 's otherwise you will get an error (try it)";
 +
$characterName = 'Casper';
 +
$ownedObject = "cat";
 +
echo "<br /><br />Where is $characterName's $ownedObject?";
 +
echo '<br /><br />Where is '.$characterName.'\'s '.$ownedObject.'?';
 +
?>
 +
 
 +
five.php
 +
<?php
 +
echo "Adding numeric values<br />";
 +
$a = 2;
 +
$b = 3;
 +
$c = $a + $b;
 +
echo "<br /><br />$a plus $b equals $c";
 +
?>
 +
 
 +
six.php
 +
<?php
 +
echo "Adding numeric values<br />";
 +
$a = “2”;
 +
$b = “3”;
 +
$c = $a + $b;
 +
echo "<br /><br />$a plus $b equals $c";
 +
?>
 +
 
 +
seven.php
 +
<?php
 +
$output = "There once was ";
 +
$output .= "a blue frog who ";
 +
$output .= "was very serious about";
 +
$output .= "playing guitar. ";
 +
$output .= "He lived happily ever after. ";
 +
$output .= "The end. ";
 +
echo "<br /><br />$output";
 +
?>
 +
 
 +
 
 +
 
 +
 
 +
eight.php
 +
<?php
 +
$output = "There once was ";
 +
$output .= "a blue frog who ";
 +
$output .= "was very serious about";
 +
$output .= "playing guitar. ";
 +
$output .= "He lived happily ever after. ";
 +
$output .= "The end. ";
 +
 
 +
//comments are just like in ActionScript & JavaScript
 +
$password = "hello";
 +
//$password = "bye";
 +
if ($password == "hello") {
 +
echo "<br /><br />$output";
 +
} elseif($password == "bye") {
 +
echo "Goodbye!";
 +
}else {
 +
echo "yipes! there is no valid password!";
 +
}
 +
?>
 +
 
 +
nine.php
 +
<?php
 +
//character names
 +
$frogName = "Henry J. Frog";
 +
$fishName = "sarina k. littlefish";
 +
 
 +
//printing out names as-is
 +
echo "<br />$frogName";
 +
echo "<br />$fishName";
 +
 
 +
//using ucwords()
 +
$fishName = ucwords($fishName);
 +
echo "<br />Now using ucwords function:";
 +
echo "<br />$fishName";
 +
 
 +
//using strtoupper()
 +
$fishName = strtoupper($fishName);
 +
echo "<br />Now using strtoupper function:";
 +
echo "<br />$fishName";
 +
 
 +
 
 +
?>
 +
 
 +
ten.php
 +
<?php
 +
//custom function
 +
function sayHello($saying, $day) {
 +
$greeting = "On a day like today, $day, I always like to think $saying - don't you?";
 +
return $greeting;
 +
}
 +
echo "Hello. ".sayHello("yipes!", "Thursday");
 +
?>
 +
</pre>
  
 
==Homework==
 
==Homework==

Revision as of 16:09, 22 August 2006


Class 8

Web Forms

HTML Form Example

Simple GET

This is a simple example of an html form that has two text fields. One called FirstName and one called LastName. The two fields are sent via a get request to an aspx apge that displays the results.

http://iam.colum.edu/AIM/class8/simpleGet.html

Here is the simpleGet.aspx source for those that are interested

Simple POST

Same a the simple GET page except the page uses a POST instead of a get. Notice that the variables do not show up in the querysting to the action page. The variables here are sent in the http header. You may also notice there is a subtle change in the way that aspx read these varibales.

http://iam.colum.edu/AIM/class8/simplePost.html

Here is the simplePost.aspx source for those that are interested

All HTML input types http://iam.colum.edu/AIM/class8/htmlFormExample.html

PHP

1.Backstory 2.acronym 3.structure 4.open-source (and what that means) 5.timeline: 1994, 1998 (3.0), 2000 (4) and 5 6.server-side vs. client-side 7.server-side processing 8.delimiters 9.functions 10.parameters 11.echo shortcut (<?=”output”;?> 12.variables (& datatypes – strings, numeric, and boolean) ex: $variableName 13.variable naming conventions (don'ts: starting with _ or numbers) 14.line termination (just like actionscript & javascript) 15.quotes – double and single(#4) 16.escape characters \n linefeed and \r carriage return \t horizontal tab \\ backslash \$ dollar sign \” double quote and \' single quote 17.numeric values (example) 18.concatenating multiple lines using .= 19.conditional statements 20.more functions(ucwords, strtoupper) 21.custom functions Misc notes: editors to use, resources to explore, etc.

Code examples:

one.php
<?php
phpinfo();
?>

two.php
<?php
$variable1 = "value of variable 1";
$variable2 = "value of variable 2 with $variable1 embedded";
echo $variable2;
?>
three.php
<?php
$variable1 = "value of variable 1";
$variable2 = "Value of variable 2 with $variable1 embedded";
echo $variable2;
echo "<br />Double quotes are strange because you can express the value of a variable by just referencing the variable name in a string, ";
echo "<br />and single quotes can be confusing when concatenating variable values.";
$variable3 = 'single quote variable 3';
$variable4 = '<br />variable 4 with $variable3 referenced (but not displayed unless you concatenate it like so: '.$variable3.')';
echo $variable4;
?>

four.php
<?php
echo "To use a single quote in a double-quoted string is no problem, but it is in a single-quoted string."; 
echo "If you are using single quotes, you will need to escape the apostrophe 's otherwise you will get an error (try it)"; 
$characterName = 'Casper';
$ownedObject = "cat";
echo "<br /><br />Where is $characterName's $ownedObject?";
echo '<br /><br />Where is '.$characterName.'\'s '.$ownedObject.'?';
?>

five.php
<?php
echo "Adding numeric values<br />"; 
$a = 2;
$b = 3;
$c = $a + $b;
echo "<br /><br />$a plus $b equals $c";
?>

six.php
<?php
echo "Adding numeric values<br />"; 
$a = “2”;
$b = “3”;
$c = $a + $b;
echo "<br /><br />$a plus $b equals $c";
?>

seven.php
<?php
$output = "There once was ";
$output .= "a blue frog who ";
$output .= "was very serious about";
$output .= "playing guitar. ";
$output .= "He lived happily ever after. ";
$output .= "The end. ";
echo "<br /><br />$output";
?>




eight.php
<?php
$output = "There once was ";
$output .= "a blue frog who ";
$output .= "was very serious about";
$output .= "playing guitar. ";
$output .= "He lived happily ever after. ";
$output .= "The end. ";

//comments are just like in ActionScript & JavaScript
$password = "hello";
//$password = "bye";
if ($password == "hello") {	
	echo "<br /><br />$output";
} elseif($password == "bye") {
	echo "Goodbye!";
}else {
	echo "yipes! there is no valid password!";
}
?>

nine.php
<?php
//character names
$frogName = "Henry J. Frog";
$fishName = "sarina k. littlefish";

//printing out names as-is
echo "<br />$frogName";
echo "<br />$fishName";

//using ucwords()
$fishName = ucwords($fishName);
echo "<br />Now using ucwords function:";
echo "<br />$fishName";

//using strtoupper()
$fishName = strtoupper($fishName);
echo "<br />Now using strtoupper function:";
echo "<br />$fishName";


?>

ten.php
<?php
//custom function
function sayHello($saying, $day) {
	$greeting = "On a day like today, $day, I always like to think $saying - don't you?";
	return $greeting;
	}
echo "Hello. ".sayHello("yipes!", "Thursday");
?>

Homework

AIM Assignment 6 Web Forms

Reading

Links

http://php.net
http://www.w3schools.com/php/default.asp
http://www.w3schools.com/html/html_forms.asp