Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN 6710 - Section A – TR 9:30-10:45 CRN 10570 – Section B – TR 5:30-6:45.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
PHP File Upload ISYS 475.
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
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.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
PHP (2) – Functions, Arrays, Databases, and sessions.
Python and Web Programming
FILE UPLOADS CHAPTER 11. THE BASIC PROCESS 1.The HTML form displays the control to locate and upload a file 2.Upon form submission, the server first stores.
File uploading in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
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.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
HTML Form and PHP IST Review of Previous Class HTML table and PHP array Winner is chosen randomly using rand() function.
14. Uploading Files to MySQL Database. M. Udin Harun Al Rasyid, S.Kom, Ph.D Desain dan.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
Advanced Web 2012 Lecture 6 Sean Costain Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing.
CST336, Spring 2015 Week 8: PHP File Upload. PHP provides specific functions to handle binary data such as uploading a file into the server, storing it.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
1 HTML forms (cont.)
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
HTML Forms.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring Forms, HTML5 layout.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
HTML FORM AND PHP IST 210: Organization of Data IST210 1.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Using the HTML and CSS Validation Services
Play Framework: Introduction
PHP / MySQL Introduction
HTML Forms and User Input
Web Systems Development (CSC-215)
Building Web Applications
PHP and Forms.
Client-Server Model: Requesting a Web Page
PHP.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20
Presentation transcript:

Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45

Form Handling When creating an HTML form, there are several attributes we can set that determine how we will handle the data from the form when it is submitted Action Default is same page Method Default is “GET”, often changed to “POST” GET shows up in the URL, POST does not Enctype Set to “multipart/form-data” if you have a file upload

Form Handling On the PHP side, the data submitted by the form is stored in predefined arrays: GET : $_GET[] POST: $_POST[] Both: $_REQUEST[] You should only use $_REQUEST if you need your code to accept GET or POST data Normally we chose one method or the other for any given form submission

Form Handling Once a form is submitted, we need to have PHP validate the data in each field to confirm we are getting what we expect We often use strlen() and isset() with other basic logic to ensure each field has the data we expect If we are handling the form submission on the same page as the form, we also want to check and see if the form was even submitted before trying to validate if(isset($_POST[‘submitButtonName’]))

Form Handling Let’s set up a simple form and do some basic validation tasks

File Handling There are two types of File Handling I want to discuss today Files uploaded via a form submission Working with files on the server

File Uploads As discussed earlier, we need to set the enctype of the form so it will accept the file uploads When the form is submitted, the server takes the file and stores it in a temporary location PHP then builds another array variable with information about the file uploaded and the current temporary location/filename called $_FILES[] name, type, tmp_name, error, size

File Uploads The primary tasks we need to perform for a file upload are: Set form to accept files Validate that the file is of an allowed type/size/etc Move the file from the temp location to a permanent location During this move, we should generally set a new unique name (often we use a timestamp)

File Uploads Validating a file type is usually done based on the file extension, and not based on the “type” array element PHP provides a function for this: pathinfo(“filename.ext”, PATHINFO_EXTENSION) Generally we want to chose a small set of file types to allow, as opposed to choosing a few not to allow This is a security practice to prevent a user from uploading a malicious script/page of some type to your server

File Uploads When moving the file out of the temporary directory, we need to have a directory coded in for where it will go, and a way to ensure the filename is unique (often adding a timestamp) uploads_directory/filename_unixtimestamp.ext Then we can use a PHP function to get the file moved to where it belongs move_uploaded_file($tempName, $newPathAndName)

File Uploads Depending on what we are having the user upload, sometimes we will want the upload directory to not be visible from the web, so we create the folder at the same level as httpdocs Other times, we want to make the files accessible (often this is the case with images), so we will put the upload folder somewhere inside of httpdocs

File Handling Now that we have a file on the server, we want to access it for use on our site One simple task we can do is list all the files in a given directory scandir() is_dir()

File Handling Another task we sometimes need to do is force a file to be downloaded, instead of being opened in the browser This process can also hide the true path to the file, or access files that are not normally accessible by the browser

File Handling The readfile() command can also be used to store the contents of a file into a variable for processing by PHP (maybe reading a text file for instance) We can also use encryption and decryption functions to store the files on the server in an encrypted way, and only decrypt them when sending them as a download to an authorized user

Includes Sometimes the code for a site can get very bulky, or you end up with several functions you want to use on different pages To handle this, we can create a PHP file that isn’t designed to render as web content, but is more of a library of functions we want to be able to use include / include_once require / require_once

Includes It is very common to have these pages of functions, and often some additional constants we need to set up We can help secure these kinds of pages we don’t want the user to browse to by using: get_included_files() Which returns an array of all the pages being included We can then use this to tell if we should redirect the user, or allow the page to be included

Classes / Object Oriented Sometimes it can be helpful to build our PHP with classes to be Object Oriented The basic structure is very similar to how you might build a class using Java class MyClass { }

Classes / Object Oriented To create an object of the class, we use the ‘new’ keyword $obj = new MyClass; To access instance data or class methods, we use an arrow $obj->data1; $obj->afunction();

Classes / Object Oriented Some functions we will want to implement in our classes: public function __construct() public function __toString() We can also build classes from others (parent/child, inheritance) class MyOtherClass extends MyClass public function __construct() { parent::__construct();//calls parent constructor }

Classes / Object Oriented public/private/protected work the same as in Java public is accessible from the created object private is only accessible inside the given object protected is only accessible inside the given object and inside child objects

Classes / Object Oriented When we get into the Model, View, Controller(MVC) framework in a couple of weeks, we will be using a PHP framework that is OOP, so it is important you have a basic understanding of classes and how to use them in PHP

Lab 3 - PHP Due: Sept 24 th Create a PHP page with a simple web form Include at least: Two text fields ( ) One drop down ( ) One radio button group with at least two radio buttons ( //same name attribute will cause them to group together) A submit button

Lab 3 - PHP Set up PHP code to validate that all fields had values entered Create styled error messages if fields were not completed (for example, red text saying which field was not completed) Output the values entered on the page

Next Time MySQL Basic DB background How to create a DB in GoDaddy How to create tables How to query data in tables Sept 17 th – MySQL Sept 22 nd – No Class Sept 24 th – MySQL