In PHP, you can write a program that looks like a Rembrandt, or one that makes the dog's dinner look tidy. It's not only the mechanism of the language you need to learn to do a good job, but how to apply it.
This week, on my public PHP course
, I have a group which is very IT professional in background, and very much concerned with writing good code efficiently, with easy maintainabiliy, enhancability, and element re-use across projects. So rather that use my mores standard "here is a program to ...", I've been writing new examples with a different twist as I go.
It's easy enough to code a box on a form to echo back what was on the previous form. But remember the user may enter all sorts of special characters that you need to deal with. And remember you need to do this multiple times. And remember that you need to be able to re-present the same form if the fields aren't correctly filled. And remember you would like to reuse near-identical logic on the next page. You're looking for nicely structured code - the Rembrandt not the dinner!
• Make good use of functions.
• Have common error handling logic.
• Put everything that varies into a single specification.
• Save the common code into an include file.
• Use good error messages.
I've put the example I finished with last night up on line - the source code is here
and you can run it here
. There ARE things still to be done ...
- the error messages are common at the moment, and it's all in one file rather than using an include (a good way to do it for initial testing, after all!) (written 2007-05-10, updated 2007-05-11)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesH115 - Designing PHP-Based Solutions: Best Practice 
Short underground journeys and a PHP book - (2004-11-19) 
Crossfertilisation, PHP to Python - (2005-03-06) 
Putting a form online - (2005-03-29) 
Code and code maintainance efficiency - (2005-06-08) 
A year on - should we offer certified PHP courses - (2005-07-28) 
Robust checking of data entered by users - (2005-08-27) 
Merging pictures using PHP and GD - (2006-01-13) 
Giving the researcher power over database analysis - (2006-01-22) 
Reporting on the 10 largest files or 10 top scores - (2006-08-20) 
PHP - good coding practise and sticky radio buttons - (2006-10-17) 
Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21) 
Code quality counts - (2006-11-26) 
Maintainable code - some positive advice - (2007-01-21) 
Learning to write secure, maintainable PHP - (2007-01-25) 
Back button - ensuring order are not submitted twice (PHP) - (2007-04-28) 
Good Programming practise - where to initialise variables - (2007-05-09) 
Drawing hands on a clock face - PHP - (2007-05-19) 
Resetting session based tests in PHP - (2007-08-26) 
Easy handling of errors in PHP - (2007-08-27) 
Using a MySQL database to control mod_rewrite via PHP - (2007-10-06) 
Controlling and labelling Google maps via PHP - (2007-10-13) 
Converting from postal address to latitude / longitude - (2007-10-13) 
Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14) 
A story about benchmarking PHP - (2007-12-23) 
Efficient PHP applications - framework and example - (2007-12-28) 
Software to record day to day events and keep an action list - (2007-12-31) 
Short and sweet and sticky - PHP form input - (2008-02-06) 
PHP Techniques - a workshop - (2008-04-26) 
Defensive coding techniques in PHP? - (2008-07-02) 
Refactoring - a PHP demo becomes a production page - (2008-09-12) 
Improving the structure of your early PHP programs - (2009-05-25) 
Adding a newsfeed for your users to a multipage PHP application - (2009-06-06) 
Not just a PHP program - a good web application - (2009-09-29) 
How to build a test harness into your PHP - (2010-03-16) 
Separating program and artwork in PHP - easier maintainance, and better for the user - (2011-12-05) 
PHP sessions - a best practice teaching example - (2012-07-27) 
Filtering PHP form inputs - three ways, but which should you use? - (2012-11-18) 
Even early on, separate out your program from your HTML! - (2013-04-25) 
We not only teach PHP and Python - we teach good PHP and Python Practice! - (2013-06-18) 
Learning to program - comments, documentation and test code - (2014-11-22) 
Using an MVC structure - even without a formal framework - (2016-02-07) 
Real life PHP application using our course training MVC example - (2016-06-05)
Some other Articles
Two new pages / sitesThemes for the web siteFinding resources - some pointersImproving searches - from OR to AND?Painting a masterpiece in PHPConjugationSizing sheets and other domestic issuesDucking stool for Melksham?Sorting out for a site map