Top Banner
INLS 623 – DATABASE APPLICATION DEVELOPMENT AND INTERNET APPLICATIONS Instructor: Jason Carter
58

INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

Dec 26, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INLS 623 – DATABASE APPLICATION DEVELOPMENT AND INTERNET APPLICATIONS

Instructor: Jason Carter

Page 2: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

DOWNLOAD TECHNOLOGIES

Macs MAMP http://www.mamp.info/en/downloads/

Windows WAMP http://www.wampserver.com/en/#download-wrapper

Page 3: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INTERNET

HTML

CSS

JavaScript

AJAX

Cookies

HTTP Request

Response GET

POST Redirect

PHP SQLJavaASP.NET

Python

Page 4: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INTERNET

HTML

CSS

JavaScript

AJAX

Cookies

HTTP Request

Response GET

POST Redirect

PHP SQLJavaASP.NET

Python

ClientServer

Page 5: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

HTTP

The HyperText Transport Protocol is the set of rules to allow browsers to retrieve web documents from servers over the Internet

Page 6: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

HTTP - HYPERTEXT TRANSPORT PROTOCOL

The dominant Application Layer Protocol on the Internet

Invented for the Web - to Retrieve HTML, Images, Documents etc.

Extended to be data in addition to documents - RSS, Web Services, etc..

Basic Concept - Make a Connection - Request a document - Retrieve the Document - Close the Connection

http://en.wikipedia.org/wiki/Http

Page 7: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INTERNET

HTML

CSS

JavaScript

AJAX

Cookies

HTTP Request

Response GET

POST Redirect

PHP SQLJavaASP.NET

Python

Client

Server

Page 8: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

http://www.dr-chuck.com/page1.htm

protocol host document

CLIENT

Page 9: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLIENT/SERVER

Client

Server

Page 10: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLIENT/SERVER

Client

Server

Click

Page 11: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLIENT/SERVER

Client

Server

Click

GET http://www.dr-chuck.com/page2.htm

Request

Page 12: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLIENT/SERVER

Client

Server

Click

GET http://www.dr-chuck.com/page2.htm

Request<h1>The Second Page</h1><p>If you like, you can switch back to the <a href="page1.htm">First Page</a>.</p>

Response

Page 13: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLIENT/SERVER

Client

Server

Click

GET http://www.dr-chuck.com/page2.htm

Request<h1>The Second Page</h1><p>If you like, you can switch back to the <a href="page1.htm">First Page</a>.</p>

Response

Page 14: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

Browser Web ServerDatabase Server

Apache

PHP

MySql

Page 15: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

WHY PHP?

Easy to learn MySQL is built into PHP

PHP allows you to connect to and manipulate mysql databases.

Works great with HTML PHP and HTML are interchangeable

Page 16: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PHP

PHP: Personal Home Page PHP: Hypertext Preprocessor

Page 17: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

<h1>Hello from Dr. Chuck's HTML Page</h1><p><?php echo "Hi there.\n"; $answer = 6 * 7; echo "The answer is $answer, what "; echo "was the question again?\n";?></p><p>Yes another paragraph.</p>

SAMPLE PHP

Page 18: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

<h1>Hello from Dr. Chuck's HTML Page</h1><p><?php echo "Hi there.\n"; $answer = 6 * 7; echo "The answer is $answer, what "; echo "was the question again?\n";?></p><p>Yes another paragraph.</p>

SAMPLE PHP

Page 19: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INTERPRETED LANGUAGES

Interpreter reads code and performs operations one line at a time.

PHP InterpeterMachine

Language

Page 20: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

VARIABLES

A variable is a name that refers to a valueA name that represents a value stored in

the computer memory

Dollar signs to start variable names $age

Assignment statement: used to create a variable and make it reference data

General format is variable = expression Example: $age = 29 Assignment operator: the equal sign (=)

Page 21: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

ASSIGNMENT STATEMENT

In an assignment statement, variable receiving value must be on left side

You can only use a variable if a value is assigned to it

$message = "What’s up, Doc?”; $n = 17; $pi = 3.14159;

Page 22: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

STATEMENT

A statement is an instruction that the PHP interpreter can execute

echo “1”; $x = 2; echo $x; Output:

1 2

The assignment statement does not produce output.

All statements must end with a semicolon ( ; )

Page 23: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

EXPRESSIONS A combination of values, variables, and operators Operators are special symbols that represent

computations Addition + Subtraction – Division / Multiplication * Exponentiation **

Raises a number to a power x ** y =

Remainder (Modulus) % Performs division and returns the remainder 4%2=0, 5%2=1 Typically used to convert times and distances, and to detect odd or even numbers

Evaluate the expression: 4 + 4 Output: ?

Evaluate the expression: (4 + 4) - 3

Page 24: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

EXPRESSIONS

A combination of values, variables, and operators

Operators are special symbols that represent computations

Addition + Subtraction - Multiplication * Division / Reminder (Modulus) %

Performs division and returns the reminder 4%2 = 0 5%2 = 1

Page 25: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

ORDER OF OPERATIONS

Follows same rule of precedence as mathematics

PEMDAS Parentheses Exponentiation Multiplication and Division Addition and Subtraction

Evaluate the expression: (4 + 4) - 3

Page 26: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PHILOSOPHY OF PHP

• You are a responsible and intelligent programmer

• You know what you want to do

• Lets make this as convenient as possible

• Sometimes errors fail silently

Page 27: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CONNECTING TO MYSQL<?php

$servername = "localhost";$username = "root";$password = "root";$dbname = "classicmodels";

// Create connection$conn = new mysqli($servername,

$username, $password, $dbname);

// Check connectionif ($conn->connect_error) {

die("Connection failed: " . $conn-

>connect_error);}?>

Page 28: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

SELECTING FROM A TABLE

<?php$servername = "localhost";$username = "root";$password = "root";$dbname = ”classicmodels";

// Create connection$conn = new mysqli($servername, $username,

$password, $dbname);

// Check connectionif ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

$sql = "select * from customers";$result = $conn->query($sql);}?>

Page 29: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

<?php$servername = "localhost";$username = "root";$password = "root";$dbname = ”classicmodels";

// Create connection$conn = new mysqli($servername, $username,$password, $dbname);

// Check connectionif ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

$sql = "select * from customers";$result = $conn->query($sql);

//if the number of rows are greater than 0if ($result->num_rows > 0) {

//while there are rows while($row = $result->fetch_assoc()) { echo $row['customerNumber']." ".

$row['customerName']." ".$row['contactFirstName']." ".$row['contactLastName'];

echo "<br />"; echo "<br />”; }

}}//close the connectionmysqli_close($conn);?>

Page 30: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

LIST TABLES<?php

$servername = "localhost";$username = "root";$password = "root";$dbname = "classicmodels";

// Create connection$conn = new mysqli($servername,

$username, $password, $dbname);

// Check connectionif ($conn->connect_error) {

die("Connection failed: " . $conn-

>connect_error);}?>

Page 31: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

SELECTING DATA

<?php$servername = "localhost";$username = "root";$password = "root";$dbname = ”classicmodels";

// Create connection$conn = new mysqli($servername, $username,

$password, $dbname);

// Check connectionif ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

$sql = ”show tables from $dbname";$result = $conn->query($sql);}?>

Page 32: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

<?php$servername = "localhost";$username = "root";$password = "root";$dbname = ”classicmodels";

// Create connection$conn = new mysqli($servername, $username,$password, $dbname);

// Check connectionif ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

$sql = "select * from customers";$result = $conn->query($sql);

//if the number of rows are greater than 0if ($result->num_rows > 0) {

//while there are rows while($row = $result->fetch_row()) { echo $row[0]; echo "<br />”; }

}}

//close the connectionmysqli_close($conn);

?>

Page 33: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PHP ARRAYS AND MYSQL

Stores items in a sequence one after another Stores multiple values in a single variable

PHP retrieves records from a MySQL database table and stores them in an array

Store Stores multiple values in a single variable

PHP retrieves records from a MySQL database table

Page 34: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INSERTING DATA<?php

//variables that will be inserted into the database $number = mt_rand(9000,1000000); $customerNumber = $number; $customerName = "The Little Shop that Could"; $contactFirstName = "Alex"; $contactLastName = "Becky"; $phone = "555555555"; $addressLine1 = "City that never sleeps"; $addressLine2 = ""; $city = "Chapel Hill"; $state = "NC"; $postalCode = "27514"; $country = "US"; $salesRepEmployeeNumber = 1056; $creditLimit = 2000.00;?>

Page 35: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

<?php

$sql = "insert into customers values ('$customerNumber','$customerName', '$contactFirstName', '$contactLastName', '$phone', '$addressLine1', '$addressLine2', '$city', '$state', '$postalCode', '$country', '$salesRepEmployeeNumber', '$creditLimit')";

//execute the queryresult = $conn->query($sql);?>

Page 36: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

<?php

if($result){ echo "New record created successfully";}else { echo "Error: " . $sql . "<br>" .

mysqli_error($conn);}

mysqli_close($conn);?>

Page 37: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INSERTING DYNAMIC DATA

Use HTML forms to collect data

<form></form>

Form tags contain html elements There are many html elements

Input Text Radio submit

Page 38: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INPUT TEXT TAGS

<form>First name:<br><input type="text" name="firstname"><br>Last name:<br><input type="text" name="lastname"></form>

Page 39: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INPUT SUBMIT TAG

<form action="action_page.php">First name:<br><input type="text" name="firstname" value="Mickey"><br>Last name:<br><input type="text" name="lastname" value="Mouse"><br><br><input type="submit" value="Submit"></form>

Page 40: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

SUBMIT

Sends the values of the input tag (not the submit button) to the server

The action tag determines which file processes the values from the input tag <form action="action_page.php">

How?

Page 41: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PASS VALUES TO SERVER/PHP

GET (default) form submission is passive (like a search engine

query), and without sensitive information GET is best suited to short amounts of data. Size

limitations are set in your browser

action_page.php?firstname=Mickey&lastname=Mouse

<form action="action_page.php” method=“GET”>

Page 42: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PASS VALUES TO SERVER/PHP

POST form is updating data, or includes sensitive

information (password) POST offers better security because the submitted

data is not visible in the page address

<form action="action_page.php" method="POST">

Page 43: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

HOW DOES PHP GET THE VALUES?

Superglobals Built in variables that are available at all scopes

$GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION

Page 44: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PHP $_POST

Collects form data after submitting the HTML from using post

<form action="action_page.php”method = “POST”>

First name:<br><input type="text" name="firstname" value="Mickey"><br>Last name:<br><input type="text" name="lastname" value="Mouse"><br><br><input type="submit" value="Submit"></form>

echo $_POST[‘firstname’];

echo $_POST[‘’lastname’];

Page 45: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PHP $_GET

Collects form data after submitting the HTML from using post

<form action="action_page.php”method = “GET”>

First name:<br><input type="text" name="firstname" value="Mickey"><br>Last name:<br><input type="text" name="lastname" value="Mouse"><br><br><input type="submit" value="Submit"></form>

echo $GET[‘firstname’];

echo $GET[‘’lastname’];

Page 46: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

DISPLAY ORDERS

Look at file displayOrders.php

Page 47: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PRACTICE

Create an html form that allows a user to search for a customer by state

Page 48: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PRACTICE

Create an html form that allows a user to enter information into the employee table

Page 49: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

PRACTICE

Create an html form that allows a user to enter a quantity in stock and see all products that are below that quantity

Create an html form that allows a user to enter a quantity in stock and see all products that are above that quantity

Page 50: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

HOMEWORK

Create a database that allows students to register for classes. People Addresses Students Class_Subjects Instructors Classes Student_Classes Instructors_Classes

Create web forms that allow administrators to input information into the tables.xs

Page 51: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

People person_id address_id first_name middle_name last_name date_of_birth home_phone cell_phone email_address

Page 52: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

ADDRESSES

address_id street_address1 street_address2 city state zip

Page 53: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

STUDENTS

Student_id major_subject_code minor_subject_code year_of_graduation

Page 54: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLASS_SUBJECTS

subject_code subject_name subject_description (Business studies)

Page 55: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

CLASSES

class_id subject_code start_date end_date number_of_sets

Page 56: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INSTRUCTORS

instructor_id Qualifications

Page 57: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

INSTRUCTOR_CLASSES

class_id instructor_id

Page 58: INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.

STUDENT_CLASSES

subject_class_id class_id student_id grade