2.2. Passing Information from One Page to the Next

No matter how the user gets from one page to the next, you might need information from the first page to be available on the next page. With PHP, you can move information from page to page with one of the following methods:

  • Passing information using HTML forms: You can pass information in a form. This method is most appropriate when you need to collect information from a user.

  • Adding information to the URL: You can add specific information to the end of the URL of the new page. This method is most appropriate when you need to pass only a small amount of information.

Information passed using these methods is passed to the next page. However, if the user goes to a third page, the information isn't available unless you pass again, from the second to the third page, using one of these methods again. If you want information to be available on many Web pages, you can store it in a cookie or a session so that it's available from any page on the Web site. Storing information for use on any Web page is discussed in the section "Making Information Available to All Pages in the Web Site," later in this chapter.

2.2.1. Passing information in a form

When the user clicks the submit button in an HTML form, the information in the form is sent to the script specified in the action attribute of the <form> tag. The script can store the information, ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.