1

From the implementation point of view for a database, is it preferable to handle optional form fields by setting to some default value (e.g. false, 0, "", etc.) or just ignore such fields (do nothing with the specific attribute)

So supposing you have a form of

  • firstname* (textbox)
  • lastname* (textbox)
  • What type of ice-cream do you like? (textbox)
  • If you like ice-cream, do you like flakes as well? (checkbox)

Where firstname and lastname are required values (and suitably validated). In the form processing is it a "better idea"(TM) to automatically set values for icecream_type and flakes_are_the_best_thing_ever if no such values exit? Is it preferable for an implicitly boolean type such as the checkbox inputs, or indeed those relating to text, to have explicit false values instead of nulls?

Bearing in mind that prepared statements to mitigate against SQL injection will normally consider all aspects of the form for insertion

e.g. $pdoexec->prepare("INSERT INTO person (firstname, lastname, icecream_type, flakes_are_the_best_thing_ever")

While SQL statements will normally select all attributes from a particular table

SELECT firstname, lastname, icecream_type, flakes_are_the_best_thing_ever FROM person

At what point should these non-values be handled: pre-processing (before they get near the database) or post-processing (after the fact)?

Stumbler
  • 123
  • 1
  • 4

0 Answers0