Larry Ullman

Translating Geek Into English

On Books

I’m very much a book person, I have been ever since college. You might think this would be the case as I write books for a living, but for many people there can be a big discrepancy between what you do and what you like to do. So, not only do I write books, but I love reading books; reading anything, really.

All that being said, although I do read computer books by other authors, even on the same subjects as I’ve written about, I just don’t think it appropriate for me to discuss or review these other works. I may make an occasional comment here or there, but generally I avoid doing so. There are two reasons why: first, I have an inherent conflict of interest, particularly when it comes to books on similar subjects as mine (i.e., competing books). Second, while everyone has different expectations of a book, as a person that makes much of his living doing technical writing, my expectations are likely more particular than most.

My Sabbatical

As I’ve previously mentioned in my newsletter, I’ve just wrapped the third edition of my “PHP for the World Wide Web: Visual QuickStart Guide” book and, at this moment, don’t even have another book lined up for the first time in literally several years. I expect I’ll do another book or two in 2009 but no contract has been signed yet, so I’ve got some well-earned downtime ahead of me. Of course, down time is a relative thing.

I do have two or three Web sites to do in 2009, but even a fairly complex site requires much less of me than a full-on book, so I don’t consider those to be major hurdles. Plus, I need to keep my skills up and use new sites as an opportunity to try and learn new things. So how will I be spending most of my so-called sabbatical?

Checking for Form Submissions in PHP

One important topic in PHP is how to know when to handle a form’s submission. If you have two pages–page.html and handle_page.php–the assumption is that whenever handle_page.php is accessed, it’s handling a form. This may not always be true, but is a reasonable enough assumption. However, more commonly the same page is used to both display and handle an HTML form. In such situations, that page is being accessed twice: once when the form is loaded and a second time when the form is submitted back to this same form. The trick is being able to identify which stage the page is in.

About This Blog

When I was at Microsoft’s Redmond headquarters back in May 2004 (an event I’ll write about retroactively in time), I saw one of the fellow attendees updating their blog. I remember thinking how silly it seemed: who really wants to read every little thing that a stranger writes? Coupled with my innate aversion to anything popular (I was already sick of hearing about podcasts in June 2005), I never thought I’d find myself writing a blog. In fact, when I began producing a newsletter in the Summer of 2007, I was asked why I wasn’t doing a blog instead. In part, I wanted to do a newsletter so that people would immediately receive whatever I wrote without having to repeatedly check my Web site. But I have found that a newsletter also has its downsides:

  1. I put so much pressure on myself for turning out a solid, well-written newsletter, that I’m lucky to get one out each month.
  2. Newsletters are not as conducive to feedback and interactions as I would like.
  3. Newsletters are not the best place to put code and tutorials.

So that’s what has brought me to creating this blog: it’s another way to communicate with readers and convey information. What are my hopes for this blog, then?

"PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide" E-Commerce (Chapter 13) Addendum

Chapter 13 of the book teaches most of the concepts behind doing e-commerce. It also shows you how to create a sample database, write most of the PHP scripts, and use the application from both the administrative and public sides. As I said in the book, the e-commerce application itself could not be completed because of two primary issues:

  • how the purchased product is delivered to the purchaser
  • how the money is processed

This first issue is critical for two reasons. One, there are laws regulating when people can be charged if a product is being shipped to them. Two, an administrative section still needs to be created for showing unshipped orders, marking them as shipped, and formally charging the purchaser.

The second issue is critical because there are hundreds of ways to process the money, from using something like Pay-Pal to a processing company to having your own bank handle the transaction. Each operation has its own protocol and methodology.

Using the Ternary Operator in PHP

The ternary–also called the trinary–operator is a little gem in PHP (and other programming languages) which you might run across. Its syntax is unusual at first, but it allows you to simplify more complex conditionals into one line statements.

The basic syntax of the ternary operator is:

(condition) ? 'true' : 'false';

In other words, PHP will evaluate the condition. If the condition is true, the first value–after the question mark–is returned. If the condition is false, the second value–after the colon–is returned.

The key to using this operator is understanding that a value is returned by the expression. This value must be handled, as you would handle something being returned by a function. Just two sample uses of this would be:

  • Assign a value to a variable.
<?php
$sort = (isset ($_GET['sort'])) ? $_GET['sort'] : 'asc';
?>
  • Print a message.
<?php
echo 'You entered your name as ';
echo (empty ($_POST['name'])) ? '<b>you failed to enter your name!</b>' : $_POST['name'];
?>
\['sort'\]\['sort'\]\['name'\]\['name'\]\['name'\]

is not empty.