Advanced Web 2012 Lecture 4 Sean Costain 2012. PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

PHP I.
Java Script Session1 INTRODUCTION.
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.
BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
PHP (2) – Functions, Arrays, Databases, and sessions.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
PHP: Hypertext Processor Fred Durao
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
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.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
Create an online booking system (login/registration)
Nic Shulver, Retrieving Stored Data Introduction This set of slides shows: The information source database structure The data.
1 Week Three: Using Scripts and Forms in HTML (Week Three) By Dr Fadi Safieddine.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
Advanced Web 2012 Lecture 12 Sean Costain Course Summary Sean Costain 2012 To develop skills in web design and authoring  Html 5 / CSS 3 / PHP.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
PHP Tutorial - Anas Jaghoub Chapter 2 Control Structures.
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.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Enterprise PHP – Reading Data from a DB Reading Data from a relational database in PHP Nic Shulver, FCES, Staffordshire University Using the SQLi interface.
Advanced Web 2012 Lecture 6 Sean Costain Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
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,
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP using MySQL Database for Web Development (part II)
A Guide to SQL, Seventh Edition
BASIC PHP and MYSQL Edward S. Flores.
Website Development Basics with PHP MySQL
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
More Selections BIS1523 – Lecture 9.
Number and String Operations
Building Web Applications
JavaScript.
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
Presentation transcript:

Advanced Web 2012 Lecture 4 Sean Costain 2012

PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Ref: What's it do? It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to: Reduce the time to create large websites. Create a customized user experience for visitors based on information that you have gathered from them. Open up thousands of possibilities for online tools. Allow creation of shopping carts for e-commerce websites

How to Start Sean Costain 2012 Files extension.php Index.php Gallery.php In the Code Advantage of : Decisions can be decided in code Eg if the user selects between different colours, each choice could create a differing outcome. Complex code written in PHP is never shown to the end user, all code is created on the server and the end user just gets plain HTML Allows for the connection to a database

Hello World! Sean Costain 2012 HTML PHP Both codes shown produce the same output, but if you view source, you will only see the html.

Commenting Sean Costain ways of doing this // <- this is a single line comment /* */ <- Anything between the *’s is commented, multi line comment

Variables Sean Costain 2012 A variable is a reserved memory location to store information. -Think of it as a bucket. -PHP variables always start with a $ -PHP variables aren’t strict with a specific datatype Displaying the contents of php you can use: Echo print

How to use Echo Sean Costain 2012 Echo is one of the main ways to get output to the screen. This is how you can use it by itself and with multiple variables If you are displaying text with a single quote ‘ you need to break it with a \

If … then Sean Costain 2012 If…then is used for determining choices. if the user enters in the right name, display the name otherwise, generic welcome If the number chosen is greater than 10 then apply a discount to the price

Operators Sean Costain 2012 We can use maths operators and logic to calculate for loops <less than > greater than <= less than or equal to >= greater than or equal to == equals != not equals && and || or Don’t confuse = as equals, this is the assign a value command. In programming we use ==

If … then … else Sean Costain 2012 If…then … else is used for multiple choices. if the user enters in the right name, display the name otherwise, generic welcome If the number chosen is greater than 10 then apply a discount to the price and display this information, otherwise just show the price

Switch Sean Costain 2012 Switch is like an advanced if then else statement, used for multiple conditions. What if we had different levels of discount, > 10 is 10% >20 is 20% >30 is 30%...

Loopy Loops!! Sean Costain 2012 When it comes to programming we have loops, a loop is a piece of code that runs until a certain condition is met. This is normally something like a certain number or until the system has finished reading the data in a table. Loops come in different types we have For loops While loops Do While loops <- Exists but not always used

For Loop Sean Costain 2012 The for loop is a counting loop. Repeat X until Y is matched. Say we need to display the numbers 0 through to 10 This would work, but tediousThis is cleaner and works Pretty much Optimal Now Why? What happens if it’s not 10, but 100 or 1,000 or 10,000 lines you need to display, this is the power of a loop. Write once, execute multiple times

While Loop Sean Costain 2012 A while loop is similar but doesn’t always have a defined end point. While loops are used a lot in database retrieval as the end of the table is an unknown, but it can be used for defined endpoints. Same example as before, display numbers to 10. Displaying numbers up to 10 Loops until the end of the table

Forms Sean Costain 2012 By using standard html forms, we can pass the data entered in to a php file that can then do something with the information. To read this data, you would have the following:

PHP and MySQL Sean Costain 2012 MySQL is currently the most popular open source database server in existence. On top of that, it is very commonly used in conjunction with PHP scripts to create powerful and dynamic server-side applications. When using PHP and MySQL, the first thing to do is to have a database built, in this course, the database will be constructed in phpMyAdmin. After the database is created, then you can embed MySQL into php commands to perform all of the operations needed for the website.

C.R.U.D Sean Costain 2012 CRUD – IT Loves Acronyms, this deals with databases C – Create – As in create data in a database table R – Read – As in retrieve and display the data from a database table U – Update – As in Edit the already stored information in a database table D – Delete – As in delete the data in a database table But first…. Connecting to the database Whenever you need to access to the data stored in a database, there needs to be a connection established between the page and the database. This can be done in a couple of different ways.

Connecting to a Database Sean Costain 2012 This could be done on every single page, but will get tedious This is my preferred method, with the function being stored in a separate file and then imported into the page being used. On each page, you would then call dbLink();

Create Sean Costain 2012 Creating new data into a database table The breakdown of the above line: A php variable is storing the entire MySql command INSERT into <- When coding MySQL, capitalize the command (table field, table field, table field, table field) VALUE <- store in the listed fields… (NULL, $variable, $variable, $variable,$variable) NULL is a non element, use this on primary key/auto increment fields.

Read Sean Costain 2012 Reading data from a database table The breakdown of the above lines: A php variable is storing the entire MySql command While it is not the end of the table SELECT everything (*) from the (Users) Put the table field data into the following variables Then display the name of the person

Update Sean Costain 2012 Updating data from a database table The breakdown of the above lines: A php variable is storing the entire MySql command UPDATE where the table field equals a variable the user filled out and where the table’s uid is the same as the user filled out uid. Once done, store the result of the commend in a variable

Delete Sean Costain 2012 Deleting data from a database table The breakdown of the above lines: A php variable is storing the entire MySql command DELETE from where the table table’s uid is the same as the user filled out uid. Once done, store the result of the commend in a variable