Skip to Main Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate content levelBeginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
329
these pages will self destruct...
What’s wrong with the PHP script?
Let’s take a look at lookupCustomer.php, and see where we might
be able to make some improvements.
<?php
// Connect to database
$conn = @mysql_connect(“mysql.headrstlabs.com”,
“secret”, “really-secret”);
if (!$conn)
die(“Error connecting to MySQL: “ . mysql_error());
if (!mysql_select_db(“headrst”, $conn))
die(“Error selecting Head First database: “ . mysql_error());
$phone = preg_replace(“/[\. \(\)\-]/”, “”, $_REQUEST[‘phone’]);
$select = ‘SELECT *’;
$from = ‘ FROM hraj_breakneck’;
$where = ‘ WHERE phone = \’’ . $phone . ‘\’’;
$queryResult = @mysql_query($select . $from . $where);
if (!$queryResult)
die(‘Error retrieving customer from the database.’);
while ($row = mysql_fetch_array($queryResult)) {
echo $row[‘name’] . “\n” .
$row[‘street1’] . “\n” .
$row[‘city’] . “, “ .
$row[‘state’] . “ “ .
$row[‘zipCode’];
}
mysql_close($conn);
?>
lookupCustomer.php
Remember this script from
Chapter 2? It’s the PHP
script that getCustomerInfo()
makes a request to.
It’s OK if you’re not familiar with PHP... just
get a basic idea of what’s going on, so you can
tell your PHP guys what to watch out for.
Here’s another
potential problem. The
script loops through
all the results it gets,
and displays each one...
...but the script should
never return more
than one customer.
We’ll need to x this.
Even though we get rid
of some of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
Head First Ajax

Head First Ajax

Rebecca M. Riordan

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content