PHP Week 11 INFM 603. Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not.

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Advertisements

Web Database Programming Connecting Database to Web.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
Debugging and Ajax Session 7 INFM 718N Web-Enabled Databases.
Objectives Connect to MySQL from PHP
MySQL and PHP Integration Session 6 INFM 718N Web-Enabled Databases.
JavaScript and PHP Week 10 LBSC 690 Information Technology.
PHP Programming Session 2 INFM 718N Web-Enabled Databases.
MySQL and Requirements Session 4 INFM 718N Web-Enabled Databases.
Web-Database Integration
Intermediate PHP & MySQL
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
PHP Programming Part II and Database Design Session 3 INFM 718N Web-Enabled Databases.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Create an online booking system (login/registration)
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.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
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.
Chapter 9 Using PHP with MySQL. header.html Script 9.1 on page 266 des/header.html
Lecture 10 – MYSQL and PHP (Part 2)
Programming Week 11 LBSC 690 Information Technology.
Website Development with PHP and MySQL Saving Data.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
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”
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
PHP Week 8 INFM 603. Agenda Questions PHP Drupal Project Plan.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
CS 174: Web Programming September 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Chapter 12 Cookies and Sessions Part 1. Stateless Protocol Hypertext Transfer Protocol (HTTP) is stateless No shopping cards No logging.
PHP Database Processing CIS 1715 Web Technologies.
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.
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.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Radoslav Georgiev Telerik Corporation
1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in PHP consists of a number of functions.
PHP using MySQL Database for Web Development (part II)
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
PHP and MySQL.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Software Engineering for Internet Applications
PHP.
Presentation transcript:

PHP Week 11 INFM 603

Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not for code Procedural perspective (vs. object-oriented)

Making PHP HTML stuff <?php PHP stuff ?> HTML stuff stuff---/xxxxx.php

Programming Skills Hierarchy Reusing code [run the book’s programs] Understanding patterns [read the book] Applying patterns [modify programs] Coding without patterns [programming] Recognizing new patterns

Some Things to Pay Attention To Syntax How layout helps reading How variables are named How strings are used How input is obtained How output is created Structured Programming How things are nested How arrays are used Modular Programming Functional decomposition How functions are invoked How arguments work How scope is managed How errors are handled How results are passed

Variables All variable names start with a $ –Case sensitive (assume everything could be!) Variables can hold any scalar value –Number (integer, float) –String (double quotes, \ escape character) –TRUE, FLASE –NULL Need not be declared, automatically cast

Operators in PHP Arithmetic operators + - * / Logical operators = > && || ! String concanetation operator is a dot. Different from JavaScript!

Statements in PHP Sequential {…; …;…;} Semicolons are required at the end of every statement Conditional if (3==i) {…} else {…} Loop foreach ($array as $key => $value) {…} while ($row=mysql_fetch_array(…)) {…} For ($i=0; $i<10; $i++) {…} Braces are optional around a single statement

Arrays in PHP A set of key-element pairs $days = array(“Jan”->31, “Feb”=>28, …); $months = explode(“/”, “Jan/Feb/Mar/…/Dec”); $_POST Each element is accessed by the key –$months[0]; –{$days[“Jan”]} PHP unifies arrays and hashtables –Elements may be different types

Functions in PHP Declaration function multiply($a, $b=3){return $a*$b;} Invoking a method $b = multiply($b, 7); All variables in a function have only local scope Unless declared as “global” in the function

Using PHP with (X)HTML Forms ”, size=30 /> Yes No if (isset($_POST[“submitted”])) { echo “Your address is $ .”; } else { echo “Error: page reached without proper form submission!”; }

Connecting PHP to MySQL On XAMPP: $dbc=mysql_connect (‘localhost’, ‘userid’, ‘password’); On unix: $dbc=mysql_connect(‘:/export/software/otal/mysql/run/mysqld.sock’, ‘userid’, ‘password’);

<?php # Script mysql_connect.php // Set the database access information as constants. DEFINE ('DB_USER', 'tester'); DEFINE ('DB_PASSWORD', 'tester'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection. $dbc (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: '. mysql_error() ); // Select the (DB_NAME) OR die ('Could not select the database: '. mysql_error() ); // Create a function for escaping the data. function escape_data ($data) { // Address Magic Quotes. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } // Check for mysql_real_escape_string() support. if (function_exists('mysql_real_escape_string')) { global $dbc; // Need the connection. $data = mysql_real_escape_string (trim($data), $dbc); } else { $data = mysql_escape_string (trim($data)); } // Return the escaped value. return $data; } // End of function. ?>

<?php # Script login.php (7th version after Scripts 9.1, 9.3, 9.6, & 9.14) // Send NOTHING to the Web browser prior to the session_start() line! // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('../mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for an address. if (empty($_POST[' '])) { $errors[] = 'You forgot to enter your address.'; } else { $e = escape_data($_POST[' ']); } // Check for a password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your password.'; } else { $p = escape_data($_POST['password']); }

if (empty($errors)) { // If everything's OK. /* Retrieve the user_id and first_name for that /password combination. */ $query = "SELECT user_id, first_name FROM users WHERE ='$e' AND password=SHA('$p')"; $result ($query); // Run the query. $row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable. if ($row) { // A record was pulled from the database. // Set the session data & redirect. session_name ('YourVisitID'); session_start(); $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect the user to the loggedin.php page. // Start defining the URL. $url = ' $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url.= '/loggedin.php'; header("Location: $url"); exit(); // Quit the script. } else { // No record matched the query. $errors[] = 'The address and password entered do not match those on file.'; // Public message. $errors[] = mysql_error(). ' Query: '. $query; // Debugging message. } } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional.

// Begin the page now. $page_title = 'Login'; include ('./includes/header.html'); if (!empty($errors)) { // Print any error messages. echo ' Error! The following error(s) occurred: '; foreach ($errors as $msg) { // Print each error. echo " - $msg \n"; } echo ' Please try again. '; } // Create the form. ?> Login Address: Password: <?php include ('./includes/footer.html'); ?>