From the course: PHP with MySQL Essential Training: 1 The Basics
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Solution: Validations
From the course: PHP with MySQL Essential Training: 1 The Basics
Solution: Validations
(upbeat music) - [Instructor] Hopefully you did well with the challenge assignment to do page validations. In this movie, I'm going to show you the solution that I came up with. The first thing that I did, was I created a validate page function, which takes an associative array. That's all the page attributes that we're going to be working with later and I'm going to use an errors array to keep track of any problems. Then I'm going to go through, and I'm going to check and see various attributes. I'm going to check and see if subject ID is blank. If it is blank, then I'm going to say, "Subject cannot be blank." I'm going to do the same thing for menu name, I'm going to use the same kinds of things we had on subject that it's not blank. And also check that it's between two and 255 characters. Then for position, I'm going to check and make sure it's greater than zero, but less than 999. For visible, I'm going to make sure it's either a zero or a one. And then for the content, I'm just…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.