Creating databases for Web Applications php basics. Emailing. phpMyAdmin to set up MySQL. Homework: Use phpMyAdmin. Make posting with [unique] source on.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Creating Databases applications for the Web Reprise. Basic HTML review, forms Preview: Server side vs client side Classwork: create HTML forms and check.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
Creating Databases SELECT. UPDATE. Demonstrate projects. Classwork / Homework: Prepare to choose teams & projects.
PHP: Hypertext Processor Fred Durao
Computer Concepts 2014 Chapter 7 The Web and .
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
INTERNET APPLICATION DEVELOPMENT For More visit:
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Creating databases for web applications
Server-side Scripting Powering the webs favourite services.
Creating Databases for Web Applications Work session Open Source versus Proprietary important topics HW: finish* projects. Look at final quiz guide. Final.
Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for.
Creating databases for web applications Play quizzes Testing process regular expressions: form validation PHP coding handling forms Homework: regular expressions.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
PHP meets MySQL.
Creating Databases for Web Applications cookie examples lab time: favorites cookies & Sessions class time for group work/questions on projects Next class:
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Continue with behavioral marketing. Tweets. Reports. Homework: capture tweets project.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Creating Databases applications for the Web Basic HTML review, forms Preview: Server side vs client side Flash HW: Review HTML forms and FLASH examples.
Creating databases for web applications Library. New example: student database. Homework: Complete class example. Catch up on source postings. Do creation.
Introduction to JavaScript CS101 Introduction to Computing.
XP Tutorial 8 Adding Interactivity with ActionScript.
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
Creating Databases for Web Applications State capitals quiz: demonstrates parallel structures AND multi-purpose php files Classwork: design a new quiz.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Creating Databases applications for the Web: week 2 Basic HTML review, forms HW: Identify unique source for asp, php, Open Source, MySql, Access.
ASSIGNMENT 2 Salim Malakouti. Ticketing Website  User submits tickets  Admins answer tickets or take appropriate actions.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP Overview. What is PHP Widely available scripting language Free Alternative to Microsoft’s ASP Runs on the Web Server; not in the browser Example:
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Radoslav Georgiev Telerik Corporation
Creating databases for Web Applications
CSE 103 Day 20 Jo is out today; I’m Carl
Creating Databases Local storage. join & split
PHP / MySQL Introduction
Intro to PHP & Variables
ISC440: Web Programming 2 Server-side Scripting PHP 3
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
PHP Forms and Databases.
PHP-II.
Presentation transcript:

Creating databases for Web Applications php basics. ing. phpMyAdmin to set up MySQL. Homework: Use phpMyAdmin. Make posting with [unique] source on MySql.

Reprise: PHP php files are interpreted by/on/at the server. –php code within html 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 Generally done by php using form input –HTML is produced, perhaps from data from database, and sent to the client –cookie is set and/or accessed Alternative is session data

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

php echo: prints material to the html document to be returned/sent to the client Can use print Extra credit opportunity: is there a difference?

A hello world program Somewhat contrived because it really doesn't need to run on the server. Demonstrate, show, then explain. but… will use it to illustrate how to use the query string world.phphttp://faculty.purchase.edu/jeanine.meyer/hello world.php world.php?who=curlyhttp://faculty.purchase.edu/jeanine.meyer/hello world.php?who=curly

Hello world in php <?php $who = $_GET['who']; $junk = "this is stuff that doesn't get to the html"; print ("$who wanted to say Hello, world "); ?>

php Variables start with a $. A string can contain a variable name and php will replace with the variable value! There are many associative arrays, such as $_GET and $_POST

Notes method=get produces the so-called query string. We can also generate query strings using php OR as direct call method=post sends data another way (via HTTP headers). Benefit is that less is revealed to user. Think of it also as lack of clutter.

Problem in my code? Hello world in php <?php $who = $_GET['who']; //how does this get set? $junk = "this is stuff that doesn't get to the html"; print ("$who wanted to say Hello, world "); ?>

Next We are going to create pairs of files: an html file and a php file. In this case, the html file will ask for information for sending and the php file will do it.

Storyboard send fromhtmlg.html send p.php

html to php Sets of html (set up) and php files send fromhtmlp.html –calls send p.php send fromhtmlg.html –calls send g.php send fromhtmlgfancy.html –calls send gfancy.php

Note These all look the same when viewing the displayed html The source shows that each calls a different php file! This is quick, but not instantaneous. Be patient. –It is helpful to have multiple addresses.

send fromhtmlg.html

Your (for reply) To /p> Subject Body of message (you may change it) This is sent from my own html/php application

textarea Similar to input Used for multi-line Can put in default content –Where should instructions go????

send g.php <?php $to = $_GET['to']; $subject = $_GET['subject']; $body = $_GET['body']; $headers = "From: ". $_GET['from']; if (mail($to, $subject, $body,$headers)) { echo("Your message was sent"); } else { echo("There was a problem."); } ?>

Notice $_GET is an associative array. We use square brackets with the name of the input element in the form. Similarly, $_POST is an associative array. Concatenate strings using the. operator. –REPEAT: String concatenation uses a period (dot) NOT a plus sign! Function calls use parentheses.

Question What is different for the post version?

Mechanics in php script Need to distinguish html versus php: use Concatenation of strings operator is. (period) Single quotes and double quotes can be used, but must be paired appropriately!!!! 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. Next example mixes up html and php. First the html file and then the php file. I put in some color coding. There is some color coding in TextPad and more in Sublime.

Your (for reply) To Subject Body of message (you may change it) This is sent from my own html/php application

php for sending within html This script will use php mail <?php $to = $_GET['to' ]; $subject = $_GET['subject' ]; $body = $_GET['body' ]; $headers = "From: ". $_GET['from' ]; if (mail($to, $subject, $body,$headers)) { echo( "Your message was sent" ); } else { echo( "There was a problem." ); } ?> This is after the php

Exercise Write a pair of files. One html and one php. The html file has a form with action pointing to the php file. You can build on the send files. You can do other things, like sending to the giving and also to another you know…. NOT MINE! Make it work!

geolocation example meyer/ ing/geolocationkm .htmlhttp://socialsoftware.purchase.edu/jeanine. meyer/ ing/geolocationkm .html Look at code—focus on form

Your (for reply) To Subject: Body of message (you may change it) My geolocation is at the address given in the subject line.

<?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."); } ?>

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)

For information about php and MySQL <?php ob_start(); // buffering output phpinfo(); $phpinfo = ob_get_contents(); //get contents echo $phpinfo; //print out as html ?> infotest.php

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

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

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

So… Try writing [yet another] html file calling a php file that uses $_Request

Checking if a form variable has been set Common situation to check if this is first time Prevents error if no value exists

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.

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)

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 (" "); Preview: SQL statements require quotation marks around values in certain cases. SQL statements use a single equals sign (=) for checking for equality. JavaScript and php use == in IF statements.

Claim All database management systems share similar structure. –Tables Records Fields –Records have primary keys –Records may have fields that hold foreign keys, that is, pointers to records in other tables or in that table. They differ on efficiencies noticeable in large[r], production systems –How many simultaneous queries –Security issues

Pre Banner example (NOT ACCURATE) Table of courses: Each record represents one course. Course identifier: MAT3530 Cross-listing: NME3520 Name: Creating Databases for Web Applications ASSUMING a course has at most one pre- requisite, each record has field that Pre-req: MAT1420 NOTE: the pre-reqs are more complicated, since there are many possibilities. This would require a new table.

Creating database Create tables [Create / specify relations.] If database to be used on stand-alone computer, create Forms, Queries, Views. Instead, we will create programs (html and php scripts) to do this.

Table Define what is a record in the table: what are the fields? –What is the information associated with this one thing? What is the data type of each field? –If the databases will contain many records, may be important to be careful as to size Is there an intrinsic primary key (unique for the record in the table) or should system supply one? Fields can have at most one value (can be null) –Multiple values means you need another table

Caution Defining (designing) a database is not trivial. May require revision. Interview process with clients/customers/systems owners can take time.

What should we do? Budget (past and future expenses, dates) Favorite web sites Music collection (with features) Courses taken (grades) / will take Candidates ?

Spreadsheet vs Database Scale: DBMS can handle large amounts of information Efficiency: DBMS can handle different datatypes DBMS have facilities for MANAGING access by multiple users DBMS supports multiple tables and queries across the multiple tables. MySQL (and other DBMS) have easier (?) connections to php and other programming languages –Extra credit opportunity: do posting on php and Excel or php and Open Office or VB.net & xls, etc. Give explanation / examples, NOT JUST THE LINK!

Preview Team projects: take one of my sample projects at b/examples.html b/examples.html understand and present to class make enhancements

Admission There is (at least) one problem in the trivia quiz involving questions.

Trivia game Questions table –Question id –Question text –Question answer –Question category –Question score Player table History table

Trivia database: players Player id Player name Player password

Trivia database: history Event id Player id Question id Result (right or wrong) Time stamp

Entity Relationship Diagram Questions Ques id Text Answer Category score Players Player id Player name Password History historyID Ques id Player id Result Time stamp

phpMyAdmin Used to set up tables for your / my one database –Can also do this entirely using php code After setting up table, we will then use php for adding, deleting and query-ing records in the tables. Can use phpMyAdmin to see what is in the tables

Homework To do examples, you need to upload to your server account. –Get html examples working if you haven't done so –Experiment with phpMyAdmin First use regular password, then id and password given in README file Required: Find a good source on MySql and make posting. [Continue review of HTML/HTML5] Next class: parallel structures