Consider an application which takes Customer info, Order info, then Destination info.
First I'd collect a Customer ID, then I'd go to the Customer Form to ensure the address, etc. is accurate.
If this is the first time the Customer form is being presented, I'll query a MySQL table corresponding to the Customer table. If a matching row is found, I'll put the result in a $_SESSION Array, then the HTML has fields which look like this:
Code: Select all
<input name="firstname" value="<?= $_SESSION['Customer']['firstname'] ?>" >Each Form Action takes the $_POST[] data and validates what has been entered, passing the $_POST values to the same array so we can access the info later, or repopulate the fields if an error was detected - if there is an error the user gets 'bounced back' to the form for another try.
All is well and good so long as a record is found prior to the first presentation of the form. IF there is NO record, however, I currently have hard coded a list of field names in my script and I populate those Array elements with blanks (to avoid the nasty Var not Found warnings).
So I'm looking for a dynamic way (to be included in a function) to get all the field names from my Customer table, then if any field does not exist in my array, I can fill the array elements in with a blank "on the fly" - thus avoiding the need to hard code every 'blank' for every field for every table.
Any ideas? Thanks in advance for your help!