Using PHP
To work through the examples in this chapter and the rest of the book, you need access to a web server with PHP installed.To gain the most from the examples and case studies, you should run them and try changing them.To do this, you need a testbed where you can experiment.
If PHP is not installed on your machine, you need to begin by installing it or having your system administrator install it for you.You can find instructions for doing so in Appendix A,“Installing PHP5 and MySQL5.” Everything you need to install PHP under Unix or Windows can be found on the accompanying CD-ROM.
Creating a Sample Application: Bob’s Auto Parts
One of the most common applications of any server-side scripting language is processing HTML forms.You’ll start learning PHP by implementing an order form for Bob’s Auto Parts, a fictional spare parts company.You can find all the code for the examples used in this chapter in the directory called chapter01 on the CD-ROM.
Creating the Order Form
Bob’s HTML programmer has set up an order form for the parts that Bob sells.This relatively simple order form, shown in Figure 1.1, is similar to many you have probably seen while surfing. Bob would like to be able to know what his customers ordered, work out the total prices of their orders, and determine how much sales tax is payable on the orders.
[Script will be posted later on]
Notice that the form’s action is set to the name of the PHP script that will process the customer’s order. (You’ll write this script next.) In general, the value of the action attribute is the URL that will be loaded when the user clicks the Submit button.The data the user has typed in the form will be sent to this URL via the method specified in the method attribute, either get (appended to the end of the URL) or post (sent as a separate message).
Also note the names of the form fields: tireqty, oilqty, and sparkqty.You’ll use these names again in the PHP script. Because the names will be reused, it’s important to give your form fields meaningful names that you can easily remember when you begin writing the PHP script. Some HTML editors generate field names like field23 by default.They are difficult to remember. Your life as a PHP programmer will be easier ifthe names you use reflect the data typed into the field.
You might want to consider adopting a coding standard for field names so that all field names throughout your site use the same format.This way, you can more easily remember whether, for example, you abbreviated a word in a field name or put in underscores as spaces.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment