PHP on a Fast Track and other web development techniques a quick introduction to web programming by...
-
Upload
marshall-stephens -
Category
Documents
-
view
217 -
download
2
Transcript of PHP on a Fast Track and other web development techniques a quick introduction to web programming by...
![Page 1: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/1.jpg)
PHP on a Fast Trackand other web development techniques
a quick introduction to web programmingby Jarek Francik
![Page 2: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/2.jpg)
Teaching Objectives
• To ensure everyone of you have at least basic understanding of server-side processing
• To introduce some basic PHP• To demonstrate what makes a
good web project (and what doesn’t)
![Page 3: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/3.jpg)
What is a project?
A project is a temporary endeavour undertaken to create
a unique product or service
![Page 4: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/4.jpg)
A project is...• a defined, unique venture or undertaking, that• requires the effort or activities of people• who have defined roles and responsibilities• within a finite life-span, time-scale or schedule• using specified resources and budgets, and• has specific goals or objectives to achieve• to which measures of quality can be applied• that brings about some change in the status quo• to provide sustainable benefit to some business, organisational or
individual need
![Page 5: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/5.jpg)
Project Snettisham
![Page 6: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/6.jpg)
Project Snettisham
Research:• 50,000 birds swirling like smoke clouds• Oystercatchers, godwits, knots...• Snettisham RSPB Reserve in Norfolk• Best time: autumn, when most birds migrate
LOOK FOR MORE INFORMATION!
![Page 7: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/7.jpg)
Project Snettisham
Research (cont.):• The flocks take to the air as the high tide races in,
covering their feeding grounds. They sit out high tide and return once the tide falls
• Spectaculars happen only in the mornings• The higher the tide
the better chances to see it!
![Page 8: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/8.jpg)
Project Snettisham
• Need a really high tide early in the morning...• UK Tides (Apple Store)
USE PROPER TOOLS!
![Page 9: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/9.jpg)
![Page 10: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/10.jpg)
![Page 11: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/11.jpg)
Project Snettisham
• Need a really high tide early in the morning...• UK Tides (Apple Store)• Timetables ready on the RSPB site!
USE VARIOUS SOURCES OF INFORMATION
![Page 12: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/12.jpg)
Project Snettisham
• Need a really high tide early in the morning...• UK Tides (Apple Store)• Timetables ready on the RSPB site!• Three days trip 17-19 Nov
(to also see the Pink Footed Geese!)
PLANNING IS CRUCIAL
![Page 13: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/13.jpg)
Project Snettisham
• Need a really high tide early in the morning...• UK Tides (Apple Store)• Timetables ready on the RSPB site!• Three days trip 17-19 Nov
(to also see the Pink Footed Geese!)• Accommodation!
PLANNING IS CRUCIAL
![Page 14: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/14.jpg)
![Page 15: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/15.jpg)
Project Snettisham
• Need a really high tide early in the morning...• UK Tides (Apple Store)• Timetables ready on the RSPB site!• Three days trip 17-19 Nov to see the
Pink Footed Geese as well!• Accomodation!• Transport...• Anything else...
PLANNING IS CRUCIAL
![Page 16: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/16.jpg)
What is a project?
A project is a temporary endeavour undertaken to create
a unique product or service
• Snettisham Trip is a project• A trip to Winkworth Arboretum last Saturday
wasn’t a project
why?
![Page 17: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/17.jpg)
What is a project?
A project is a temporary endeavour undertaken to create
a unique product or service
• A bespoke e-commerce solution for a company who need it is a project
• A novel HCI solution is a project• A routine PC maintenance is not a project
why?
![Page 18: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/18.jpg)
What is a project?
A project is a temporary endeavour undertaken to create
a unique product or service
• A typical on-line store for a small company...hardly is a good project
why?
![Page 19: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/19.jpg)
PHP on a Fast Track
![Page 20: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/20.jpg)
Client & Server
Client Server
![Page 21: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/21.jpg)
Client & Server
Client Server
![Page 22: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/22.jpg)
Client & Server
Client Server
Remote File System
![Page 23: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/23.jpg)
Client & Server
Client Server
REQUEST: GET
RESPONSE: HTML
Remote File System
![Page 24: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/24.jpg)
Client & Server
CLIENT SIDE PROCESSING
Client Server
REQUEST: GET
RESPONSE: HTML
Files served over the network may contain HTML, CSS, JavaScript,Flash and may be pretty much complex!
Remote File System
![Page 25: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/25.jpg)
Client & Server
Client Server
REQUEST: GET
RESPONSE: HTML
Remote File System
![Page 26: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/26.jpg)
Client & Server
Client Server
REQUEST: GET
RESPONSE: HTML
Remote File SystemREQUEST: GETRESPONSE: HTML
![Page 27: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/27.jpg)
Client & Server
Client Server
REQUEST: POST
RESPONSE: HTML
Remote File SystemRESPONSE: HTML
REQUEST: POST
DB
![Page 28: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/28.jpg)
Client & Server
Client Server
REQUEST: POST
RESPONSE: PHP
Remote File SystemREQUEST: POSTRESPONSE: PHP
DB
SERVER SIDE PROCESSING
Great Hiking ShoePerfect Company
![Page 29: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/29.jpg)
Client-Side Processing Server-Side Processing
DB
![Page 30: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/30.jpg)
Client-Side Processing• Executed locally, on client’s
computer• Results visible immediately
• Fast & dynamic• Processing within a single
webpage• Information cannot be shared• No Databases*• Keeping things secret is very
difficult – everything is on the user’s computer* Limited local database functionality is available in HTML5, but without sharing
Server-Side Processing• Executed remotely, on
a web server• Results must be sent over the
network• Network latency• Pages must be re-loaded in
order to view the results*• Information easily shared• Database back-end• Flexible and powerful security
control * AJAX technology allows for remote updates without pages being reloaded but technically it is a combination of server side and client side technologies
![Page 31: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/31.jpg)
PHP
• Scripting language for web development• Created by Rasmus Lerdorf 16 years ago• Currently phasing out• Easy to learn but time-consuming to use
![Page 32: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/32.jpg)
Let’s writea shopping cart application
![Page 33: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/33.jpg)
What do we need?
• Operating System• Web Server• Database• Scripring Language
Windows, Linux, MacOS...Appache, IIS, WEBrick...MySQL, Postgres, SQLite, Oracle...PHP, Perl, Python, Ruby, C#, Java...
DB
![Page 34: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/34.jpg)
What do we need?
• Operating System• Web Server• Database• Scripring Language
Windows, Linux, MacOS...Appache, IIS, WEBrick...MySQL, Postgres, SQLite, Oracle...PHP, Perl, Python, Ruby, C#, Java...
DB
![Page 35: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/35.jpg)
What do we need?
• Operating System• Web Server• Database• Scripring Language
Linux, Windows, MacOS...Appache, IIS, WEBrick...MySQL, Postgres, SQLite, Oracle...PHP, Perl, Python, Ruby, C#, Java...
DB
![Page 36: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/36.jpg)
What do we need?
• Operating System• Web Server• Database• Scripring Language
MacOS, Windows, Linux...Appache, IIS, WEBrick...MySQL, Postgres, SQLite, Oracle...PHP, Perl, Python, Ruby, C#, Java...
DB
![Page 37: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/37.jpg)
What do we need?
• Operating System• Web Server• Database• Scripring Language
X - PlatformAppacheMySQL PHP Perl
DB
![Page 38: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/38.jpg)
What do we need?
• Operating System• Web Server• Database• Scripring Language
XAM P P
DB
![Page 39: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/39.jpg)
XAMPP
http://www.apachefriends.org/en/xampp.html
or google for “xampp”
![Page 40: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/40.jpg)
XAMPP
1. Download and install – it’s easy2. Run XAMPP Control Panel3. Start Apache & MySql4. Run in your browser:
http://localhost5. Click Explore and go
to htdocs to browseyour web files
6. Use MySql Admin tosetup your databasewith mySqlAdmin
![Page 41: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/41.jpg)
phpMyAdmin
![Page 42: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/42.jpg)
phpMyAdmin
![Page 43: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/43.jpg)
phpMyAdmin
![Page 44: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/44.jpg)
phpMyAdmin
![Page 45: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/45.jpg)
phpMyAdmin
![Page 46: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/46.jpg)
phpMyAdmin
![Page 47: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/47.jpg)
KU Server
• There is a web server available for you at
http://studentnet.kingston.ac.uk
• Find all details there (or check the end of this presentation)
![Page 48: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/48.jpg)
Database structure (SQL)USE test; CREATE TABLE goods ( id int(6) unsigned NOT NULL auto_increment, item varchar(100) NOT NULL default '', price decimal(6,2) NOT NULL default '0.00', image varchar(100) NOT NULL default '', PRIMARY KEY (id) );
INSERT INTO goods VALUES (1, 'Soap', '4.99'); INSERT INTO goods VALUES (2, 'Strawberry Jam', '1.99'); INSERT INTO goods VALUES (3, 'Toothpaste', '2.49'); INSERT INTO goods VALUES (4, '8GB Memory Stick', '22.99');
![Page 49: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/49.jpg)
The First PHP File<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html><head>
<title>Your Cart</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head> <body> <h1>Your Cart</h1> <?php
?></body></html>
cart.php0
![Page 50: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/50.jpg)
The First PHP File<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html><head>
<title>Your Cart</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head> <body> <h1>Your Cart</h1> <?php echo "Hello, world!"; ?></body></html>
cart.php
![Page 51: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/51.jpg)
Another File: Front Page<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head>
<title>Your Shop</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head><body> <h1>Your Shop</h1> <ul> <li><a href="cart.php?action=add&id=1">Add item #1 to the cart</a></li> <li><a href="cart.php?action=add&id=2">Add item #2 to the cart</a></li> <li><a href="cart.php?action=add&id=3">Add item #3 to the cart</a></li> <li><a href="cart.php?action=add&id=4">Add item #4 to the cart</a></li> </ul> <p><a href="cart.php?action=show">Show your cart</a></p></body></html>
index.php1
![Page 52: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/52.jpg)
What the application should do
• http://localhost/cart.php?action=show• http://localhost/cart.php?action=add&id=2
![Page 53: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/53.jpg)
What the application should do
• http://localhost/cart.php?action=show• http://localhost/cart.php?action=add&id=2
<?php $action = $_GET['action']; $id = $_GET['id']; echo "<p>DEBUG: Action to do is $action, and item id is $id.</p>";?>
cart.php1
![Page 54: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/54.jpg)
Make information persistent
• HTTP as a stateless protocolprotocol with no memory of who you are
• Cookies• Sessions• Session variables
$_SESSION['cart']
Name of the variable
Collection of session variables
![Page 55: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/55.jpg)
Make information persistent<?php session_start(); ?> must appear in the
first line (before DOCTYPE)
cart.php
![Page 56: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/56.jpg)
Make information persistent<?php session_start(); ?>
......
<?php $cart = $_SESSION['cart']; $action = $_GET['action']; $id = $_GET['id'];
echo "<p>DEBUG: Action to do is $action, and item id is $id.</p>"; if ($action == 'add') { $cart = $cart . ",$id"; $_SESSION['cart'] = $cart; } echo "<p>DEBUG: Cart is: $cart</p>";?>
must appear in the first line (before
DOCTYPE)
cart.php2
![Page 57: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/57.jpg)
Display Your Cart<?php $cart = $_SESSION['cart']; $action = $_GET['action']; $id = $_GET['id'];
if ($action == 'add') { $cart = $cart . ",$id"; $_SESSION['cart'] = $cart; } $myitems = explode(',', $cart); // explode using comma as a separator if (count($myitems) <= 1) echo "<p>Your cart is empty.<p>"; else foreach ($myitems as $i) if ($i != '') { echo "<p>Item id: $i</p>"; }?>
cart.php3
![Page 58: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/58.jpg)
Connect to the Database<?php $hostname = 'localhost'; // localhost is the URL of the server $username = 'root'; // the username in this example is root $password = 'elvis'; // put here your MySQL root password // connect to the database server $con = mysql_connect($hostname, $username, $password) or die ('Could not connect: ' . mysql_error()); // display if connection failed mysql_select_db("test", $con); // choose the test database ...
cart.php
![Page 59: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/59.jpg)
Connect to the Database<?php $hostname = 'localhost'; // localhost is the URL of the server $username = 'root'; // the username in this example is root $password = 'elvis'; // put here your MySQL root password // connect to the database server $con = mysql_connect($hostname, $username, $password) or die ('Could not connect: ' . mysql_error()); // display if connection failed mysql_select_db("test", $con); // choose the test database ...
Provide the proper username & password
(the latter maybe ‘’)
cart.php
![Page 60: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/60.jpg)
Display Your Items.... foreach ($myitems as $i) if ($i != '') { $result = mysql_query("SELECT * FROM goods WHERE id = $i"); $row = mysql_fetch_array($result); $item = $row['item']; $price = $row['price']; echo "<p>$item: £$price</p>"; }?>
cart.php4
![Page 61: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/61.jpg)
Final Polishings
cart.php:• Better HTML formatting• Total price of the cart calculated
index.php:• Connected to the database
![Page 62: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/62.jpg)
<?php session_start(); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html><head>
<title>Your title here</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><!--<link rel="stylesheet" type="text/css" href="style.css" />-->
</head> <body> <h1>Your Cart</h1><?php $hostname = 'localhost'; // localhost is the URL of the server $username = 'root'; // the username in this example is root $password = 'elvis'; // put here your MySQL root password // connect to the database server $con = mysql_connect($hostname, $username, $password) or die ('Could not connect: ' . mysql_error()); // display if failed mysql_select_db("test", $con); // choose the test database $cart = $_SESSION['cart']; $action = $_GET['action']; $id = $_GET['id']; if ($action == 'add') { $cart = $cart . ",$id"; $_SESSION['cart'] = $cart; }
$myitems = explode(',', $cart); // explode using comma as a separator
if (count($myitems) <= 1) echo "<p>Your cart is empty.<p>"; else { echo "<table>"; $total = 0; foreach ($myitems as $i) if ($i != '') { $result = mysql_query("SELECT * FROM goods WHERE id = $i"); $row = mysql_fetch_array($result); $item = $row['item']; $price = $row['price']; $total += $price; echo "<tr><td>$item</td><td>£$price</td></tr>"; } echo
"<tr><td><strong>Total</strong></td><td><strong>£$total</strong></td>";
echo "</tr></table>"; }?><p>[<a href="index.php">Home Page</a>]</p> </body></html>
cart.php
![Page 63: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/63.jpg)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<?php $hostname = 'localhost'; // localhost is the URL of the server $username = 'root'; // the username in this example is root $password = 'elvis'; // put here your MySQL root password // connect to the database server $con = mysql_connect($hostname, $username, $password) or die ('Could not connect: ' . mysql_error()); // display if failed mysql_select_db("test", $con); // choose the test database ?> <html> <head> <title>Your Shop</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!--<link rel="stylesheet" type="text/css" href="style.css" />--> </head>
<body> <h1>Your Shop</h1> <table> <?php
$result = mysql_query("SELECT * FROM goods");while ($row = mysql_fetch_array($result)){
$id = $row['id']; $item = $row['item']; $price = $row['price']; echo "<tr>";echo "<td>$item</td>";echo "<td>£$price</td>";echo "<td><a href=\"cart.php?
action=add&id=$id\">add to cart</a></td>";echo "</tr>";
};mysql_free_result($result);
?> </table> <p><a href="cart.php?action=show">Show your
cart</a></p> </body></html>
index.php
![Page 64: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/64.jpg)
Other Possible Options
• PHP• ... ???
![Page 65: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/65.jpg)
Other Possible Options
• PHP• ASP.NET• Java• Python• Perl• Ruby on Rails
So, which way to go?
![Page 66: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/66.jpg)
The goal of this lecture isto show that PHP
is rarely a good choice!
![Page 67: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/67.jpg)
Online Store Created with Ruby on Rails
watch at:http://vimeo.com/30927971
![Page 68: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/68.jpg)
How to do a good web project?How to avoid a bad web project?
• PHP is still popular for some simple tasks• There are some really powerful frameworks
written in PHP – e.g. Magento (Open Source)• PHP is now 17 years old! (1995 - 2012)
consider something newer!
![Page 69: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/69.jpg)
How to do a good web project?How to avoid a bad web project?
• Writing a web app from scratch is anachronism!
?
![Page 70: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/70.jpg)
How to do a good web project?How to avoid a bad web project?
• Writing a web app from scratch is anachronism!
• Research – use various sources of information• Use proper, modern tools• Planning is crucial• Wherever possible, build on top of something
other people did
![Page 71: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/71.jpg)
How to do a good web project?How to avoid a bad web project?
On-Line Store:• a bespoke solution in PHP – from scratch• a bespoke solution in Rails – from scratch,
but with substantial support from the framework• open source solution: Magento (as )• hosted solutions: Shopify, Volusion
build something exciting on top of available systems
![Page 72: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/72.jpg)
So what to choose?
• Your project should be based on what you learned during the course
• It doesn’t mean you must not learn anything new!
• Use your experience, do a research, READ,be brave!
• Try to do something unique
![Page 73: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/73.jpg)
THE END
![Page 74: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/74.jpg)
How to use studentnet
![Page 75: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/75.jpg)
How to use studentnet
• Your personal website is http://studentnet.kingston.ac.uk/~k01234567(provide your correct k-number)
• To upload files, you will need a FTP client program to send your files to the server.
Here are configuration settings for Filezilla:– Host: studentnet.kingston.ac.uk– Protocol: SFTP– User: k01234567 (your normal k number)– Password: ******** (your normal password)
![Page 76: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/76.jpg)
How to use studentnet• To configure your database:
go to Database Management Tool (link available at the main page http://studentnet.kingston.ac.uk, login with your standard KU knumber and password).
• First time, you will be asked to configure the name of your database and the password – remember them!
• You will then be able to Manage Database. Use your KU k-number and the database password (you created it in the previous point).
• You will find yourself in phpMyAdmin. Use it to create faces table and populate it with data, exactly the same as we did it with XAMPP
![Page 77: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/77.jpg)
How to use studentnet
• Before uploading your application you have to setup the connection for the new server – see the example below (do it for each PHP file that connects to the DB):
$hostname = 'studentnet.kingston.ac.uk'; // URL of the server $username = ‘k01234567'; // replace with your real username$password = ‘elvis'; // your MySQL database password should go here // connect to the database server $con = mysql_connect($hostname, $username, $password) or die ('Could not connect: ' . mysql_error()); // display if connection failed mysql_select_db("db_k01234567", $con); // replace with your real db name
![Page 78: PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.](https://reader034.fdocuments.net/reader034/viewer/2022042821/56649cff5503460f949d0996/html5/thumbnails/78.jpg)