Chapter 8. When Things Go Wrong (and They Will)
You have a growing set of functional scripts. You have some web pages that interact with them, CSS to style both your HTML static pages and the HTML that your scripts dish out, and you could (and should) go in and add some client-side JavaScript validation. Things are looking pretty good.
But thereâs a monster lurking in the deep. Even though youâve occasionally added a die
or a conditional to ensure that your queries return a result row, your code really assumes the perfect user: one who always types exactly what you expect, never enters a phone number in the email field or spaces in the Facebook URL field; someone who never needs to go backâand in fact never clicks her browserâs Back button at an inopportune timeâand never enters her information into the same form twice by furiously clicking âAdd my informationâ instead of waiting on her lousy Internet connection.
Of course, if you start thinking about your friends and family, you probably donât know a lot of those types of users. And thatâs a problemâ¦a big problem. The reality of web softwareâand in fact any type of softwareâis that people will always find ways to break your best-intended pages, forms, and scripts. Theyâll supply you bad information, leave out required fields, and make a general mess of anything and everything.
Note
Again, client-side JavaScript is worth a strong mention here. You can reduce a lot of this sort of problem by validating your ...
Get PHP & MySQL: The Missing Manual, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.