So far, we've been adding the functions to the end of the PHP file. That makes them difficult to share, though.
Let's put the functions in a separate file, in a
library folder. Let's all the file...
useful-functions.php. Any name will do.
I'll also put our CSS files in the
useful-functions.php has to have a start-php thing at the top:
Sometimes I forget that.
Now, I'll add one line to the main PHP program.
- require_once 'library/useful-functions.php';
- // Set up vars to track results.
- $errorMessages = ''; // Composite error messsage.
There are other ways to include files, but we'll only use
Oh, the CSS file moved into
- <link rel="stylesheet" href="library/styles.css">
That's it! Now, we can reuse the validation functions as needed.
Reuse your code across programs, using functions and page components.
That's it for validation. Now lets talk about databases.