Faculty of Sciences and Social Sciences HOPE PHP – Working with Input Stewart Blakeway FML 213

Slides:



Advertisements
Similar presentations
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
Advertisements

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.
Video, audio, embed, iframe, HTML Form
HTML Form and PHP IST Review of Previous Class HTML table and PHP array Winner is chosen automatically using rand() function.
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
Faculty of Sciences and Social Sciences HOPE User Sessions & The Include Statement Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Functions in PHP Stewart Blakeway FML
Tutorial 6 Working with Web Forms
16/19/2015CS120 The Information Era CS120 The Information Era Chapter 5 – Advanced HTML TOPICS: Introduction to Web Page Forms and Introductory Javascript.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Creating a Dynamic Web Site Stewart Blakeway FML 208
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
ITM © Port, Kazman1 ITM 352 HTML Forms, Basic Form Processing.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
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.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
ACM Web Development Workshop - PHP By Luis Torres.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Week 7. Lecture 3 PHP Forms. PHP forms In part 2 of this course, we discussed html forms, php form is similar. Lets do a quick recap of the things we.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Faculty of Sciences and Social Sciences HOPE JavaScript Advanced Stewart Blakeway FML
HTML Forms. Today’s Lecture We will try to understand the utility of forms on Web pages We will find out about the various components that are used in.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Website Development with PHP and MySQL Saving Data.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 HTML Forms
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
76 © 1998, 1999, 2000 David T. Gray, Howard Duncan, Jane Kernan Frames When displaying information in a browser, it is sometimes useful to divide the display.
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.
CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: MUHD EIZAN SHAFIQ BIN ABD AZIZ FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
PHP Form Introduction Getting User Information Text Input.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Web Technology HTML and PHP.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
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.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
PHP Form Processing * referenced from
HTML FORM AND PHP IST 210: Organization of Data IST210 1.
Form Data (part 2) MIS 3502, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/10/2015 Slide 1.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro to PHP & Variables
Web Systems Development (CSC-215)
Presentation transcript:

Faculty of Sciences and Social Sciences HOPE PHP – Working with Input Stewart Blakeway FML 213

Faculty of Sciences and Social Sciences HOPE What will we cover To review how to create HTML input forms How to access user input How to handle multiple selections Form submission Reading in Files and Interpreting To learn how to pass data from HTML forms to PHP scripts – Externally – Internally Each lecture we cover, you should be thinking how this will apply to your assessment

Faculty of Sciences and Social Sciences HOPE Forms User input is more often than not obtained using forms and form elements What happens to the data from the form is dictated by the action attribute in the form tag

Faculty of Sciences and Social Sciences HOPE A Simple HTML Form Name: Address: Address of Envelope: form_listings.php Contents of Envelope: information for user information for address user Stewart

Faculty of Sciences and Social Sciences HOPE What happens if you click send? In this case the form will attempt to send the data to a PHP page called form_listing What happens if the page does not exist? Not Found The requested URL /form_listing.php was not found on this server. Apache/ (Win32) PHP/4.3.3 Server at localhost Port 80

Faculty of Sciences and Social Sciences HOPE form_listings.php <?php echo "Hello ".$_POST[‘user’]." "; echo "Your Address is:".$_POST[‘address’]; ?> user Stewart

Faculty of Sciences and Social Sciences HOPE Let ’ s break it down Name: Address: <?php echo "Hello ".$_POST[‘user’]." "; echo "Your Address is:".$_POST[‘address’]; ?> Two Separate Files Creates a single global variable – an array! The array has two elements NORMALLY you would move to a local variable

Faculty of Sciences and Social Sciences HOPE Radio Buttons <?php $myLocalVariable = $_POST[‘radiobutton’]; echo ( “ selected was: ”. $myLocalVariable); ?>

Faculty of Sciences and Social Sciences HOPE The values passed The values passed so far have been one value per control. The same principles apply to all form elements that pass one value What if we wanted to pass more than a single value from a predefined list. For example a select control list or check boxes?

Faculty of Sciences and Social Sciences HOPE The Code Name: Address: Networks and Operating Systems Web Site Development IT Business Applications Database Technology

Faculty of Sciences and Social Sciences HOPE This produces name=“user” Stewart name="address" Somewhere in Liverpool name=“course[]” Networks and Operating Systems Website Development

Faculty of Sciences and Social Sciences HOPE <?php echo "Hello ".$_POST[‘user’]." "; echo "Your Address is: ".$_POST[‘address’]; if (!empty($_POST[‘course’])) { echo " "; foreach ($_POST[‘course’] as $value) { echo " ".$value." "; } echo “ ”; } ?> Form Listing What will be echoed out? Try to remember, the value stored is not necessarily what the user sees!

Faculty of Sciences and Social Sciences HOPE Form Listing <?php echo "Hello ".$_POST[‘user’]." "; echo "Your Address is: ".$_POST[‘address’]; if (!empty($_POST[‘course’])) { echo " "; foreach ($_POST[‘course’] as $value) { echo " ".$value." "; } echo “ ”; } ?>

Faculty of Sciences and Social Sciences HOPE Form Listing <?php echo "Hello ".$_POST[user]." "; echo "Your Address is: ".$_POST[address]; if (!empty($_POST[course])) { echo " "; foreach ($_POST[course] as $value) { echo " ".$value." "; } echo “ ”; } ?>

Faculty of Sciences and Social Sciences HOPE PHP File Handling Part of your assessment requires you to read input from a file – List of Students to automatically enrol on a course – Questions in a Quiz Outputting to a file is also useful – Students enrolled on a course (for registers?) – Student Marks

Faculty of Sciences and Social Sciences HOPE PHP File Handling - Opening a File <?php $file=fopen(“list.txt","r"); ?>

Faculty of Sciences and Social Sciences HOPE PHP File Handling - Opening a File <?php $file=fopen("list.txt","r") or exit("Unable to open file!") ; ?>

Faculty of Sciences and Social Sciences HOPE PHP File Handling – Reading from the file <?php $file = fopen("list.txt","r"); fgets($file); ?> fgetc($file);

Faculty of Sciences and Social Sciences HOPE PHP File Handling – Reading from the file <?php $file = fopen("list.txt","r"); echo (fgets($file)); $line = fgets($file); ?>

Faculty of Sciences and Social Sciences HOPE PHP File Handling – Closing a File <?php $file = fopen("test.txt","r"); $line = fgets($file); fclose($file); ?>

Faculty of Sciences and Social Sciences HOPE PHP File Handling – End of File? PHP can check to determine if it is the end of file. feof($file); if (feof($file)) { echo (“End of File Reached”); } while (!feof($file)) { $line = fgets($file); } echo (“End of File Reached”);

Faculty of Sciences and Social Sciences HOPE Passing Data to the Same Page Sometimes you may want to pass data to the same page Consider the following example – If submit not clicked display form – Else do something with data (typically you will add to the database)

Faculty of Sciences and Social Sciences HOPE The Structure if ($_POST[viewed] != "yes") { // display form for input } else { // process data } if (isset ($_POST[‘formElementName’])) { // process data } else { // display the form for input }

Faculty of Sciences and Social Sciences HOPE Requirements action in the form needs to be set to $_SERVER[‘PHP_SELF’] the form needs a hidden field called viewed – or if using isset an existing form element viewed must be set to yes once the form has been displayed – or a value associated with the form element Works better once you begin using functions! This will be revisited

Faculty of Sciences and Social Sciences HOPE What have we covered? Forms Recap Passing data as a global variable Accessing the data from the global variable Radio Buttons Multiple Selections File Input We also touched on Flow Control and Arrays. These are covered in much more detail over the next few weeks.

Faculty of Sciences and Social Sciences HOPE Any Questions?