Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending email working: both html and Flash!

Similar presentations


Presentation on theme: "Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending email working: both html and Flash!"— Presentation transcript:

1 Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending email working: both html and Flash!

2 PHP php files are interpreted by/on/at the server. One or more of the following happens: –php interface to operating system is used to do things such as interact with databases OR files OR email –HTML is produced (and sent to the client) –cookie is set and/or accessed

3 Structure CLIENT Browser (Firefox): Requests URL SERVER PHP interpreter SERVER DBMS (MySQL) Build HTML page

4 Mechanics in php script Need to distinguish html versus php Common task will be to generate a string (aka character string) made up of html you know ahead of time and html generated from variables.

5 phpinfo script PHP info test <? echo phpinfo(); ?>

6 Variables Concept in all computing Variable 'is' a name that holds a value. Can be used in place of a literal value. The value can vary over use PHP: variable names begin with $, no spaces, avoid punctuation except for _ Rule: long enough for you to remember what it is used for and short enough to type.

7 php example Test Welcome to the store <?php …. Print(" New Products "); Print( " "+$newproduct1name); ?> Variable set & used

8 php variables within strings For all php variables, you can put the variable name in a string: print("The name input was: $fname"); –php figures out that $fname is a variable and gets its value. NOTE: out of habit in using other programming languages, sometimes I don't do that: print ("The name input was :". $fname); NOTE: the string concatenation operator is. Caution: SQL often requires a single quotation mark

9 Form data in php Built-in functions $_GET[' '] $_PUT[' '] If you want to NOT distinguish (considered less secure) $_REQUEST[' '] Name in form

10 Checking if a form variable has been set Common situation to check if this is first time $saywhich=@$_GET['saywhich']; Prevents error if no value exists

11 random rand (a, b) returns a pseudo-random choice from a to b, inclusive $choice=rand(0, sizeOf($states)-1); The arrays in php (like JavaScript and ActionScript) start indexing at zero.

12 Overview Useful to think in terms of 3 language domains (my terminology): –client side browser (interpreter of html) –server side interpreter of asp/JavaScript or php (There is another level here for the operating system, but this is what the asp objects and the php built-in functions & variables provide.) –database interpreter of SQL (by Access or MySQL)

13 Warnings Applicable to php and other languages: To output quotation marks in the HTML, you may use single quotes or 'escape' double quotation marks: print (" "); Response.Write(" "); SQL statements require quotation marks around values in certain cases. SQL statements use a single equals sign (=) for checking for equality. asp/JavaScript and php use == in IF statements.

14 php file for sending email Note: this file can be used from HTML and from Flash / ActionScript Must execute on server Could use post or get [or $_REQUEST] This is what is used in Catching Bo

15 sendemail.php <?php $to = $_POST['to']; $subject = $_POST['subject']; $body = $_POST['body']; $headers = "From: ". $_POST['from']; if (mail($to, $subject, $body,$headers)) { echo("Your message was sent"); } else { echo("There was a problem."); } /* message is send even if email(s) not good! */ ?>

16 Extra credit possibility Figure out how to get an error Note: the use of mail is an asynchronous operation: initiated from php (sent to operating system on the server)

17 Look at Flash Download source of Catching Bo http://newmedia.purchase.edu/~Jeanine/a s30/chasebothedogemaila.flahttp://newmedia.purchase.edu/~Jeanine/a s30/chasebothedogemaila.fla

18 Look at html http://newmedia.purchase.edu/~Jeanine/db/ htmlemail.htmlhttp://newmedia.purchase.edu/~Jeanine/db/ htmlemail.html Note use of textarea element for multiline input

19 HTML Send email From To Subject Body

20 Homework Implement your versions of BOTH the HTML and the Flash for sending email Note: need to upload the sendemail.php file and the.html file and the swf and html file published from FLASH


Download ppt "Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending email working: both html and Flash!"

Similar presentations


Ads by Google