Case Study: Adding Sessions to the Winestore

In this section we use sessions to improve the user interaction with the client entry <form> developed in Chapter 6. The improvements focus on the interaction when the <form> is submitted and fields don’t validate. We modify the scripts to:

  • Display error messages on the client entry <form>

  • Use session variables to pass back the submitted fields to the <form> generation script, saving the user rekeying all the data to correct the errors

Improving the Client Entry <form>

The client entry <form>, generated by the script shown in Example 6-7, collects client fields to either create a new client or edit the details of an existing client. The script shown in Example 6-8 performs the server-side validation of the client <form> data, and updates or inserts a row in the customer table if there are no errors.

If the validation fails, the script shown in Example 6-8 generates a page to display the errors to the user, and the user then follows a hypertext link back to the client entry <form> to reenter the fields. The solution provided by Example 6-7 and Example 6-8 suffers three problems:

  • The user is forced to reenter the entire client entry <form> from scratch when an error is encountered during validation

  • The errors that are encountered during validation are displayed by Example 6-8 and not the entry <form> where they would be useful

  • The error page generated by Example 6-8 isn’t safe from the reload problem described in Chapter 6

In this section ...

Get Web Database Applications with PHP, and MySQL 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.