CSC 405: Web Application Engineering II9.1 Web programming using PHP What have we learnt? What have we learnt? Sending emails using PHP Sending emails.

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

PHP I.
PHP for Server-Side Preprocessing Chapter 08. Overview and Objectives Present a brief history of the PHP language Discuss how PHP fits into the overall.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG.
PHP (2) – Functions, Arrays, Databases, and sessions.
Website Development & Management PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT Fall
Intermediate PHP & MySQL
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
PHP on a Fast Track a quick introduction to PHP programming by Jarek Francik.
PHP & MySQL Mahak Arora Vivek Bangera. Outline How PHP works Basic scripting in PHP Forms in PHP(GET & POST Variables) SQL basics PHP and MySQL connection.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
15. User Authentication, Form Validation, Paging. M. Udin Harun Al Rasyid, S.Kom, Ph.D
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
PHP: Hypertext Processor Fred Durao
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
SQL | PHP Tutorial at 8am. god, it’s early.. SQL intro There are many different versions of SQL available for usage. Oracle MySQL SQLite DB2 Mimer The.
CSC 405: Web Application And Engineering II 2.1 Web Programming with PHP Introduction to Web programming Introduction to Web programming The programming.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP MySQL Introduction
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
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.
PHP meets MySQL.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
CSC 405: Web Application And Engineering II7.1 Database Programming with SQL Aggregation and grouping with GROUP BY Aggregation and grouping with GROUP.
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
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.
CAKEPHP Blog tutorial. what you’ll need examples/blog/blog.html 2  A running web server  A database server.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Chapter 6: Authentications. Training Course, CS, NCTU 2 Overview  Getting Username and Password  Verifying Username and Password  Keeping The Verification.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
CSC 2720 Building Web Applications Server-side Scripting with PHP.
14. Uploading Files to MySQL Database. M. Udin Harun Al Rasyid, S.Kom, Ph.D Desain dan.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
Enterprise PHP – Reading Data from a DB Reading Data from a relational database in PHP Nic Shulver, FCES, Staffordshire University Using the SQLi interface.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
CSC 405: Web Application Engineering II6.1 Database Programming with SQL What have we learnt? What have we learnt? Four site categories Four site categories.
CSC 405: Web Application Engineering II Web programmering using PHP What have we learnt? What have we learnt? Cookies Cookies Sessions Sessions User Tracking.
CSC 405: Web Application Engineering II Course Preliminaries Course Objectives Course Objectives Students’ Learning Outcomes Students’ Learning Outcomes.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
CSC 405: Web Application Engineering II5.1 Web programming using PHP What have we learnt? What have we learnt? Motivation for validating user input (form.
CSC 405: Web Application Engineering II10.1 Web programming using PHP What have we learnt? What have we learnt? Dates in PHP Dates in PHP – Various date.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
CSC 405: Web Application Engineering II 2.1 Web Programming with PHP Introduction to Web programming Introduction to Web programming The programming language.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
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.
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Tutorial 6 PHP & MySQL Li Xu
Presentation transcript:

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 using PHP Text substitution using regular expressions Text substitution using regular expressions Example: Extending the mailing list service to send s Example: Extending the mailing list service to send s Example: Restaurant rating service Example: Restaurant rating service Introduction to exercises Introduction to exercises

CSC 405: Web Application Engineering II9.2 Web programming using PHP OVERVIEW: A PHP file: <html> Hello World Hello World Hello "; Hello "; echo " WORLD "; echo " WORLD ";?> </html>

CSC 405: Web Application Engineering II9.3 Until now: Variables, numbers, strings and arrays Variables, numbers, strings and arrays Computations Computations if-constructs and loops if-constructs and loops Functions and code reuse Functions and code reuse Entering user data using forms Entering user data using forms Validating user data using regular expressions Validating user data using regular expressions Database access (MySQL) from PHP scripts Database access (MySQL) from PHP scripts

CSC 405: Web Application Engineering II9.4 Example: Send me an The following service, consisting of an HTML form and a simple PHP script, allows a user to send s to the administrator of a Web site. The file sendmail.html: Send me an Send me an Subject: Subject: Your Your Message: Message: Note: The file sendmail.php is action for the HTML form The file sendmail.php is action for the HTML form Form variables that are transferred: subject, and text Form variables that are transferred: subject, and text

CSC 405: Web Application Engineering II9.5 Example: Send me an —continued The recipient would for instance see this From: Subject: Hi Martin To: Date: Thu, 18 Apr :09: It is easy to send s using PHP However, the recipient is able to detect where the really originates: X-From-Line: Mon Oct 27 15:11: Received: from tarzan ([unix socket]) (authenticated user=mael bits=0) by tarzan (Cyrus v2.1.14) with LMTP; Mon, 27 Oct :11: Received: from localhost (localhost.localdomain [ ]) by mail.itu.dk (Postfix) with ESMTP id 4459DAB954 for ; Mon, 27 Oct :11: (CET) Received: from (superman.itu.dk [ ]) by mail.itu.dk (Postfix) with ESMTP id 9DD2CAB8CE for ; Mon, 27 Oct :11: (CET)

CSC 405: Web Application Engineering II9.6 Example: Send me an —continued To: Subject: Hi Martin From: Message-Id: Message-Id: Date: Mon, 27 Oct :11: (CET) It is easy to send s using PHP

CSC 405: Web Application Engineering II9.7 Text substitution using regular expressions Using the PHP function ereg_replace we can replace substrings in a string with other strings. A call to the function ereg_replace(r, d, s), returns the string s, but with the string d substituted for those substrings in s that match r. Example: Suppose the variable $text contains the string "Dear NAME,\nHere is some news for you, NAME:" Then the function call ereg_replace("NAME", "Peter", $text); will return the string "Dear Peter,\nHere is some news for you, Peter:"

CSC 405: Web Application Engineering II9.8 Example: Extending the mailing list example— continued Step 3: Constructing Web forms and site maps Step 4: Constructing PHP-files for implementing data transactions The files maillist3.php, maillist3_send.html, maillist3_send.php,...

CSC 405: Web Application Engineering II9.9 Extending the mailing list example—continued The file maillist3_send.html: <HTML><BODY> Send s (version 3) Send s (version 3) Use the string NAME to have member’s name appear in Use the string NAME to have member’s name appear in Message: Message: Password: Password: </HTML>Note: Only users that know the password can send out ! Only users that know the password can send out ! The form action is the file maillist3_send.php The form action is the file maillist3_send.php

CSC 405: Web Application Engineering II9.10 Extending the mailing list example—continued The file maillist3_send.php: <? include("mydb.php"); // Include utilities if ( $passwd != "hi" ) { error("Go back and enter the correct password!"); } if ( ereg(’^[:.0-9a-zA-ZæøåÆØÅ/,[:space:]-]+$’, $text) == 0 ) { error("Go back and enter a valid text!"); } mydb_connect(); // Connect to the database $rows = mysql_query("SELECT ,name FROM maillist"); // Extract rows while ( $row = mysql_fetch_row($rows) ) { // Iterate through the rows $text2 = ereg_replace("NAME", $row[1], $text); mail($row[0], "News from My.com", $text2, "From: echo "Message to $row[1] has been sent "; }echo " Proceed "; ?> ?>

CSC 405: Web Application Engineering II9.11 Yet another example: Restaurant rating Step 1: Data model CREATE TABLE restaurant ( rid int NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(200) NOT NULL ) TYPE=InnoDB; CREATE TABLE rating ( rid int NOT NULL, INDEX (rid), rating int NOT NULL, FOREIGN KEY (rid) REFERENCES restaurant (rid) ) TYPE=InnoDB; Step 2: Data transactions Inserting a restaurant: INSERT INTO restaurant (name) VALUES (’Bamboo’); INSERT INTO restaurant (name) VALUES (’Carte Dore’); INSERT INTO restaurant (name) VALUES (’Restaurationen’);

CSC 405: Web Application Engineering II9.12 Yet another example: Restaurant rating— continued Inserting a rating: INSERT INTO rating (rid,rating) VALUES (1, 3); INSERT INTO rating (rid,rating) VALUES (1, 4); INSERT INTO rating (rid,rating) VALUES (3, 6); INSERT INTO rating (rid,rating) VALUES (3, 5); Step 2: Data transactions—continued Extracting an overview—a left join with a calculation of average rating: SELECT restaurant.rid, name, AVG(rating) AS average, COUNT(rating) FROM restaurant LEFT JOIN rating ON restaurant.rid = rating.rid GROUP BY restaurant.rid, name ORDER BY average DESC;

CSC 405: Web Application Engineering II9.13 Yet another example: Restaurant rating— continued Given the inserted data, the result of the extraction is:Without GROUP BY it would be: FROM LTable LEFT JOIN RTable ON... is similar to FROM LTable, RTable WHERE... FROM LTable LEFT JOIN RTable ON... is similar to FROM LTable, RTable WHERE... LEFT JOIN includes rows in LTable that don’t match any rows in RTable, WHERE doesn’t LEFT JOIN includes rows in LTable that don’t match any rows in RTable, WHERE doesn’t

CSC 405: Web Application Engineering II9.14 Yet another example: Restaurant rating— continued Step 3: Constructing Web forms and site maps

CSC 405: Web Application Engineering II9.15 Yet another example: Restaurant rating— continued Step 4: Constructing PHP files—the file rating.php: Restaurant Ratings Restaurant Ratings Restaurant Rating Ratings Restaurant Rating Ratings <? include("mydb.php"); // Inklude utilities mydb_connect(); // Connect to database $rows = mysql_query("SELECT restaurant.rid, name, AVG(rating) AS average, COUNT(rating) AVG(rating) AS average, COUNT(rating) FROM restaurant LEFT JOIN rating FROM restaurant LEFT JOIN rating ON restaurant.rid = rating.rid ON restaurant.rid = rating.rid GROUP BY restaurant.rid, name GROUP BY restaurant.rid, name ORDER BY average DESC;"); ORDER BY average DESC;"); while ( $row = mysql_fetch_row($rows) ) { echo " $row[1] $row[2] $row[3] rate ";} rate ";}?></table> New Restaurant New Restaurant </body></html> Question: How do we display chef hats instead of a number? Question: How do we display chef hats instead of a number?

CSC 405: Web Application Engineering II9.16 Yet another example: Restaurant rating— continued Step 4: Constructing PHP files—the file rateform.php <HTML><BODY> <?include("mydb.php"); // Include utilities mydb_connect(); // Connect to the database $rows = mysql_query("SELECT name FROM restaurant WHERE rid=$rid"); $row = mysql_fetch_row($rows); echo " Rate Restaurant $row[0] echo " Rate Restaurant $row[0] Your rating: Your rating: </FORM>";?></BODY></HTML>Question: What could we do better here? What could we do better here?

CSC 405: Web Application Engineering II9.17 Yet another example: Restaurant rating— continued Step 4: Construction PHP files—the file rate.php <?include("mydb.php"); // Include utilities mydb_connect(); // Connect to the database mysql_query("INSERT INTO rating (rid,rating) VALUES ($rid, $rate)"); header("Location: rating.php"); ?>Question: What could we do better here? What could we do better here?

CSC 405: Web Application Engineering II9.18 A function for generating chef hats or stars Using recursion: function stars($n) { if ( $n < 1.0 ) return ""; else return ("*". stars($n-1)); } What is the result of the calls: stars(3) ? stars(3) ? stars(5) ? stars(5) ? stars(4.2) ? stars(4.2) ? stars(4.8) ? stars(4.8) ? stars(-1) ? stars(-1) ?

CSC 405: Web Application Engineering II9.19 Introduction to Exercise 9 During the exercise session you must construct A Web based project market... A Web based project market...