Validation
Handling errors
Using databases adds more things that can go wrong. In this lesson, we’ll see how you can handle database errors.
We’ll talk about two new types of errors:
- Database connection errors
- SQL errors
You can check for both.
We’ll also talk about simple server-side validation. Even if you can check all data on the client, you should check it on the server as well. To foil Evil Doers.
Better client-side error display
Learn:
- How to report errors in a professional way.
- How page-wide, global error messages help the user.
- How JavaScript functions make error reporting easier to program.
Form and PHP validation on one page
Learn:
- How to have the HTML for the form and the PHP validation code on the same page.
- How to collect error messages in a single variable, rather than treating them all separately.
A PHP validation function
Learn:
- How to write a PHP validation function.
- How to call it.
Complete validation
This lessons shows a complete form validation example.
- It shows good error messages.
- Some error checking is on the server side. Some is on the client side.
- Bother server-side and client-side error messages are reported in the same way. That’s done by writing PHP code that calls JavaScript code.
Validation
You know how to grab data from text fields, and do things with them. But what if the user doesn’t type anything? Or says that his or her age is -15?
In this lesson, you learn how to:
- Check whether a field has a value.
- Check whether a number is OK.
Improving validation
Learn how to do a sequence of checks on a value passed to a PHP page.
Basic server-side validation
Topics covered:
- Understand why you need server-side and client-side validation.
- Know how to check whether a value sent to the server is a valid number.
Client-side validation
Learn:
- How to get form data into JavaScript variables.
- How to check that data for errors.
- How to report errors to the user.