Section 5.6. PHP ...at a glance


5.6. PHP ...at a glance

Frank hardly took any time in updating the placeOrder.php script. It still places an order, but now it doesn't need to return any HTML. Instead, it just gives an estimate for when the pizza will arrive at the customer's front door.

     <?php     include("order.php");Frank's using a couple of other PHP files to handle order and delivery specifics. We won't look at those, but all these files are included in the book's downloadable examples.     include("delivery.php");     // Error checking     $order = $_REQUEST['order'];     $address = $_REQUEST['address'];These just get the request data.     if (strlen($order) <= 0) {Make sure we got an order that isn't an empty string.       header("Status: No order was received.", true, 400);       echo " ";       exit;     }     if (strlen($address) <= 0) {This makes sure an address was entered.       header("Status: No address was received.", true, 400);This sends a header back to the browser with an error message......and an HTTP status code indicating that an error occurred.       echo " ";Some web browsers, like Safari, report a status code of "undefined" unless there is some response from the server. By sending a blank reponse, the correct status code will be reported by those browsers.       exit;     }     // Place the order     $pizzaOrder = new PizzaOrder($order, $address);The order is created, cooked, and then prepped for delivery.     $pizzaOrder->cookOrder();     $pizzaOrder->prepOrder();     // Deliver the order     $delivery = new Delivery($pizzaOrder);     $delivery->deliver();The entire order is sent to the delivery boy, who takes care of getting it to the customer.     $deliveryTime = $delivery->getDeliveryEstimate();     echo $deliveryTime;Finally, the script finds out how long it will take for the pizza to arrive, and passes that back to the browser.     ?> 

When things go wrong

There are lots of things that can go wrong when a customer uses the Break Neck web app. Below are several problems that might come up when a customer uses the pizza order form. In each of the blanks below, write down what you think will happen when each error occurs.

Walt mistypes his phone number into the Break Neck order form, and then enters his address and order manually.

___________________________________

Maylee enters her phone number and pizza order, but accidentally changes the street number in the address field.

___________________________________

Susan enters her phone number, but accidentally clicks "Order Pizza" before she enters her pizza order.

___________________________________


Answers on page 291.




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net