TN Online TestSamacheer Kalvi practice

Forms and Files - Study Notes

Share this chapter: Telegram

Chapter Summary

This chapter shows how an HTML form and a PHP script work together to collect, check and process what a user types. Form controls such as text boxes, buttons, checkboxes, radio buttons, drop-down lists and file inputs gather the data, and the browser sends it to the web server using either the POST method, which puts the data in the body of the request, or the GET method, which adds it to the URL. The second half of the chapter covers file handling in PHP: opening, reading, writing, appending, closing and uploading files on the server.

Learning Objectives

Key Concepts and Definitions

Worked Methods

1. Collecting Form Input in PHP

Give every input element a name attribute. When the form is submitted to a PHP script, the script reads each value from a superglobal associative array, using that name as the key:

2. Server-Side File Handling Sequence

Working with a file in PHP follows the same four steps each time:

  1. Open the file: Call fopen() with the file path and a mode, such as 'r' to read or 'w' to write.
  2. Check that it opened: Make sure fopen() did not return false before you go further.
  3. Read or write: Use fread() to read the contents or fwrite() to store data.
  4. Close the file: Call fclose() to release the file handle and free the server's resources.

Common Exam Traps

Exam Tips

Solved MCQs → Practice test →

More for this chapter

Book Back Questions10 textbook MCQs · solved Additional MCQs15 extra MCQs · solved Practice TestInteractive · instant score Book Back TestTest yourself on the textbook set Additional MCQ TestTest yourself on the extra set Formula SheetAll key formulas

More chapters in Computer Applications

View all
1 Multimedia 2 An Introduction to Adobe PageMaker 3 Introduction to Database Management System 4 PHP: Hypertext Preprocessor 5 Functions and Arrays in PHP 6 Conditional Statements in PHP 7 Loops in PHP 9 Connecting PHP and MYSQL 10 Introduction to Computer Networks 11 Network Examples and Protocols 12 Domain Name System (DNS) 13 Network Cabling 14 Open Source Concepts 15 E-Commerce 16 Electronic Payment Systems 17 E-Commerce Security Systems 18 Electronic Data Interchange (EDI)