Professional web hosting - 125Chapter 7Passing Information between PagesWe use the POSTmethod

125Chapter 7Passing Information between PagesWe use the POSTmethod consistently in this book for form handling especially whenputting data into a system via a file write or SQL INSERT. We use GETonly for site navigationand Search boxes in other words, for pulling data back out of a data store and displaying it. All the rest of the forms in this chapter use the POSTmethod. Formatting Form VariablesPHP is so efficient at passing data around because the developers made a very handy but (intheory) slightly sketchy design decision. PHP automatically, but invisibly, assigns the vari- ables for you on the new page when you submit a data set using GETor POST. Most of PHP scompetitors make you explicitly do this assignment yourself on each page; if you forget to doso or make a mistake, the information will not be available to the processing agent. PHP isfaster, simpler, and mostly more goof-proof. But because of this automatic variable assignment, you need to always use a good NAMEattribute for each INPUT. NAMEattributes are not strictly necessary in HTML proper yourform will render fine without them but the data will be of little use because the HTML form-field NAMEattribute will be the variable name in the form handler. In other words, in this form:

METHOD= POST >
the text field named emailwill cause the creation of a PHP variable called $_POST[ email ] (or $HTTP_POST_VARS[ email ]if you use the older style of variable arrays; or just $emailif you have register_globals turned on) when the form is submitted. Similarly, the submitbutton will lead to the creation of a variable called $_POST[ submit ]on the next page. Thename you use in the HTML form will be the name of your variable in the PHP form handler. $HTTP_POST_VARS, $HTTP_SERVER_VARS, and the whole family of these long-form pre- defined variables are deprecated in PHP5. If you are already an experienced PHP program- mer, perhaps with a large body of previously written code lying around, you might want tothink about rewriting now for backward compatibility. They are supported for the time being, but their days are numbered. Use $_POST, $_GET, and friends instead. Remember that you cannot use a variable name beginning with a number so you should notname your form field something like 5(you laugh, but we ve seen people try to do it) andPHP variable names are case sensitive. Also, pleasetry to use informative variable namesrather than a succession of form fields named myvarand e. It s a good idea to standardize how you name form variables, to make your code more read- able and so that you spend less time flipping back to the form itself when you are supposedto be writing code to process that form. For example, you might precede all form variableswith frmto indicate their source. You might then consistently use the first few letters of eachidentifying word for what a field does, for example, frmNameFirst, frmOfficeAdd, frmHomeAdd, and so on. The specific standard you set is less important than having a stan- dard to begin with. TipCaution09
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply