TAILIEUCHUNG - PHP and MySQL Web Development - P18

PHP and MySQL Web Development - P18: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 52 Chapter 2 Storing and Retrieving Data This is very simple to do but also pretty limiting as we ll see later in this chapter. If you re dealing with information of any reasonable volume you ll probably want to use a database instead. However flat files have their uses and there are some situations when you ll need to know how to use them. Writing to and reading from files in PHP is virtually identical to the way it s done in C. If you ve done any C programming or UNIX shell scripting this will all seem pretty familiar to you. Storing and Retrieving Bob s Orders In this chapter we ll use a slightly modified version of the order form we looked at in the last ll begin with this form and the PHP code we wrote to process the order data. I Note The HTML and PHP scripts used in this chapter can be found in the chapter2 folder of this book s CD-ROM. We ve modified the form to include a quick way to obtain the customer s shipping can see this form in Figure . Figure This version of the order form gets the customer s shipping address. The form field for the shipping address is called gives us a variable we can access as address when we process the form in PHP if we have register_globals on or Opening a File 53 as _POST address or _GET address if register_globals is off see Chapter 1 PHP Crash Course for details . We ll write each order that comes in to the same file. Then we ll construct a Web interface for Bob s staff to view the orders that have been received. Overview of File Processing There are three steps to writing data to a file 1. Open the file. If the file doesn t already exist it will need to be created. 2. Write the data to the file. 3. Close the file. Similarly there are three steps to reading data from a file 1. Open the file. If the file can t be opened for example if it doesn t exist we need to recognize this and exit gracefully. 2. Read data from the file. 3. Close the file. When you want to read data from a file

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.