Join David Powers for an in-depth discussion in this video Using the exercise files, part of PHP for Web Designers.
If you're a member of lynda.com, you'll have access to the Exercise files I'll be using in this course. I have them here on my desktop in a folder called Exercise Files. There are four other folders inside the exercises files folder. Exercises, H and P-check, H and P-final. And Hansel and Petal. You can't open PHP files directly in a browser, because they need to be processed by a web server, so you need to copy these folders to the root folder of your testing server.
The location of the server root depends on your setup. I'm using on Windows, so I'm going to copy these four folders to my HTdocs folder. And let's copy those. And then go to the XAMPP folder and htdocs, which is my server root and paste them. Once you've pasted the folders, as long as the server is running the server root in a local testing environment. Can be accessed by typing localhost in a browser address bar. Follow that by a slash, and then the name of the folder, and another slash, and the name of the file.
So, I'm going to open my browser. And type local host/exercise/index.php and then press Enter or Return, and that displays an index to all the Exercise files that are used in the course. Let's just take a look at the Exercises folder and its structure itself. As a separate folder for each chapter. And if we open the chapter itself, they're numbered according to the numbers of the video.
And if we open one of those folders, you'll see that there is a file and then there's another file with underscore final. This first file is what the page will look like at the beginning of the exercise and this is what it will look like at the end of the exercise. If you type you own code in the Start file, a quick way to launch it in the browser is to open this index and then click the Start file link. And then the second link shows you what it would look like at the end of the exercise.
The Exercise files are deliberately simple, and they're designed to demonstrate a particular technique in isolation, allowing you to concentrate on the code without being distracted by complex web pages. But doing the series of exercises in isolation isn't enough in itself, so I show you how to implement those techniques. In a real website, that's what the three other top level folders are for. So let's go back and look at those folders. The hansel and petal folder contains a website for a fictitious floral design company, Hansel and Petal, that's been created entirely in static HTML.
It's not a complete site, but it contains a sufficient number of pages to feel realistic. Use this as your work folder for the practical exercises, and that's just a quick look of that Hansel and Petal site. Instead of exercises, we type Hansel and Petal. So there is the site, that we will be working with. And at the end of the course, handp_final, shows the way that the site will look, when we've finished everything.
This final version of the site is PHP InHouse, and it uses server side includes, it processes a form, displays the results with conditioning statements, and it also draws content from a database. To help you keep track with the progress through adapting the Hansel and Petal inside, the H and P check folder contains numbered folders representing what the site looks like at the end of each video. Let's take a quick look at that. If you need a fresh copy of files to follow a particular video, copy the files from the previous numbered folder, and replace your working copy, in the hansel an petal folder.
For example, if you want the files for the start of chapter four, video three, which is here. Copy the files from zero three underscore zero six and copy them into the Hansel and Petal folder. If you copy a set of files from the H and P underscore check folder, you need to make a change to one line of code in the Includes folder, to ensure that links inside the site work correctly. So let me just show you what we need to do.
It's this includes folder, and then you need to open this particular file pagedoc.php. Let's just open it, and on line four you need to change this line. Change this from handp_check and the number simply to Hansel and Petal and if you make that change all the links will work correctly within your working site. So now you know how the files are organized, let's get to work.
Note: This course was recorded with Adobe Dreamweaver, but you can use the code editor of your choice to follow along.
- How to use PHP in a webpage
- Storing and displaying text and numbers in variables
- Using functions
- Adding comments to your PHP scripts
- Moving common page elements to include files
- Displaying different content on a page
- Working with multiple values in arrays and loops
- Getting form input sent by the POST method
- Using PHP sessions to preserve data
- Storing data in session variables
- Connecting to and querying a database
- Handling errors