PHP on a Fast Track a quick introduction to PHP programming by Jarek Francik.

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG.
PHP on a Fast Track and other web development techniques a quick introduction to web programming by Jarek Francik.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
ADVM420- Class #4 Web Design with PHP and MySQL Adding and Listing from a MySQL Database.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
Basic php. Php Official site: PhP manual: Useful package (Apache, MySql,PhP):
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
INTERNET APPLICATION DEVELOPMENT For More visit:
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Multifarious Project Team Members Alberto Dominguez Nirmit Gang Jimmy Garcia Javier Handal.
SHOPPING CARTS CHAPTER 19. E-COMMERCE Typically, an e-commerce site will have public pages and admin pages.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
SQL Queries Relational database and SQL MySQL LAMP SQL queries A MySQL Tutorial and applications Database Building Assignment.
Stored Procedures, Triggers, Program Access Dr Lisa Ball 2008.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Introduction to Internet Databases MySQL Database System Database Systems.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
MySQL PHP Web Technology. Logging in to Command Line Start -> Programs -> AppServ -> MySQL Command Line Client Enter Password, then you’ll be working.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
INTERNET APPLICATION DEVELOPMENT Practical on Sessions.
CSC 405: Web Application And Engineering II9.1 Web programming using PHP What have we learnt? What have we learnt? Sending s using PHP Sending s.
Lecture 10 – MYSQL and PHP (Part 2)
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
PHP on a Fast Track a quick introduction to PHP programming by Jarek Francik last time updated in 2012.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Creating A Database Driven Website 1.Setting Up Your Web Server 2.Creating a Database 3.Creating a Webpage to Display Information From a Database 4.Creating.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
CSC 405: Web Application Engineering II9.1 Web programming using PHP What have we learnt? What have we learnt? Sending s using PHP Sending s.
CHAPTER 10 PHP MySQL Database
>> PHP: MySQL & CRUD. R ecall Database Tables Records is composed of Operations (CRUD) Create Retrieve Update Delete DBMS Access Control MySQL phpMyAdmin.
Unit 1 – Web Concepts Instructor: Brent Presley.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
ASP.NET WEB Applications. ASP.NET  Web application framework developed by Microsoft  Build dynamic data driven web applications and web services  Subset.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Basics Components of Web Design & Development Basics, Components, Design and Development.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 8 – Review Reference:
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
DEV Training Sahana Developer Training. DEV Training PHP.
Introduction to Web Development (Part 2)
IS1500: Introduction to Web Development
Introduction to Web programming
PHP / MySQL Introduction
PHP and MySQL.
ISC440: Web Programming 2 Server-side Scripting PHP 3
PHP: Database Basic Selection FdSc Module 109
Tutorial 6 PHP & MySQL Li Xu
Web Programming– UFCFB Lecture
Introduction to Web programming
Conection
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

PHP on a Fast Track a quick introduction to PHP programming by Jarek Francik

Apologies to ECommerce students: this will be more or less what you know...

Possible Options PHP ASP.NET Java Ruby on Rails Python Perl So, which way to go?

The goal of this lecture is to show that PHP is not a good technology

PHP Scripting language for web development Created by Rasmus Lerdorf 16 years ago Currently phasing out Easy to learn but time-consuming to use

Let’s write a shopping cart application

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...

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...

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...

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...

What do we need? Operating System Web Server Database Scripring Language X - Platform Appache MySQL PHP Perl

What do we need? Operating System Web Server Database Scripring Language X A M P

First thing: The Database 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');

The First PHP File <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " Your Cart Your Cart <?php ?> cart.php

The First PHP File <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " Your Cart Your Cart <?php echo "Hello, world!"; ?> cart.php

Another File: Front Page <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " Your Shop Your Shop Add item #1 to the cart Add item #2 to the cart Add item #3 to the cart Add item #4 to the cart Show your cart index.php

What the application should do

What the application should do <?php $action = $_GET['action']; $id = $_GET['id']; echo " DEBUG: Action to do is $action, and item id is $id. "; ?> cart.php

Make information persistent HTTP as a stateless protocol protocol with no memory of who you are Cookies Sessions Session variables $_SESSION['cart'] Name of the variable Collection of session variables

Make information persistent must appear in the first line (before DOCTYPE) cart.php

Make information persistent <?php $cart = $_SESSION['cart']; $action = $_GET['action']; $id = $_GET['id']; echo " DEBUG: Action to do is $action, and item id is $id. "; if ($action == 'add') { $cart = $cart. ",$id"; $_SESSION['cart'] = $cart; } echo " DEBUG: Cart is: $cart "; ?> must appear in the first line (before DOCTYPE) cart.php

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 " Your cart is empty. "; else foreach ($myitems as $i) if ($i != '') { echo " Item id: $i "; } ?> cart.php

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

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

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 " $item: £$price "; } ?> cart.php

Final Polishings cart.php: Better HTML formatting Total price of the cart calculated index.php: Connected to the database

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " Your title here --> Your Cart <?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 " Your cart is empty. "; else { echo " "; $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 " $item £$price "; } echo " Total &pound ;$total "; echo " "; } ?> [ Home Page ] cart.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " <?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 ?> Your Shop --> Your Shop <?php $result = mysql_query("SELECT * FROM goods"); while ($row = mysql_fetch_array($result)) { $id = $row['id']; $item = $row['item']; $price = $row['price']; echo " "; echo " $item "; echo " £$price "; echo " add to cart "; echo " "; }; mysql_free_result($result); ?> Show your cart index.php

Second Part: Shop created with Ruby on Rails watch at: