The information is placed in a form of hidden fields, so when the customers click the Process Order button, they are really posting the data to the final step... In this age of web site
Trang 2while ($row = mysql_fetch_array($result)) {
echo ($odd == true) ? ‘ < tr class=”odd_row” > ’ : ‘ < tr class=”even_row” >
< > Shipping: $ < ?php echo number_format($cost_subtotal, 2); ? > < /p >
< > Tax: $ < ?php echo number_format($cost_tax, 2); ? > < /p >
< > < strong > Total Cost: $ < ?php echo number_format($cost_total, 2); ? >
li > Enter Billing and Shipping Information < /li >
li > Verify Accuracy of Order Information and Send Order < /li >
li > < strong > Order Confirmation and Receipt < strong > < /li >
< /ol >
< h3 > A copy of this order has been emailed to you for your records < /h3 >
< ?php
Trang 3echo $html_body;
// send email
$headers = array();
$headers[] = ‘MIME-Version: 1.0’;
$headers[] = ‘Content-type: text/html; charset=”iso-8859-1”’;
$headers[] = ‘Content-Transfer-Encoding: 7bit’;
$headers[] = ‘From: < store@example.com >
$headers[] = ‘Bcc: < store@example.com >
mail($email, “Order Confirmation”, $html_head $html_body, join(“\r\n”, $headers));
?
4 Now to test it out Enter the site and place a few items in your shopping cart Then choose to check out You should see something that looks like Figure 15 - 4
Figure 15-4
Trang 4Figure 15-5
5 Enter your billing information, and click the button to proceed to the next step of the checkout
process Your screen should resemble Figure 15 - 5
6 Finally, click the Process Order button Your screen should resemble Figure 15 - 6
Trang 5How It Works
As you can see, checkout is a three - step process First, you allow the customer to enter his or her billing and shipping information Then, you present the information back to the customer, along with the contents of the shopping cart, for review The final step performs some database manipulation and sends an e - mail to both the customer and to you, as confirmation for the order
Taking a closer look at ecomm_checkout.php , you see it is your basic web form which collects the billing and shipping information and then posts the data to ecomm_checkout2.php This is the first step in the checkout process While you could display the form fields for both the billing and shipping areas side by side, the shipping fields aren ’ t necessary unless the addresses are different A little bit of
Figure 15-6
Trang 6JavaScript can be tied to the check - box button; if the customer wishes to use a shipping address that is
different from the billing address, the shipping area can be displayed Otherwise, it remains hidden
// update shipping table’s visibility
t.style.display = (c.checked) ? ‘none’ : ‘’;
}
ecomm_checkout2.php accepts the incoming posted data, presents it back for review, and inserts it
into a form full of hidden fields To make sure all the data is passed along to the next step, you check
to see if $_POST[ ‘ same_info ’ ] is set This means the shipping information (if any) that was sent
should be disregarded and set the same as the billing information
The information is placed in a form of hidden fields, so when the customers click the Process Order
button, they are really posting the data to the final step
< form method=”post” action=”ecomm_checkout3.php” >
div >
< input type=”submit” name=”submit” value=”Process Order”/ >
< input type=”hidden” name=”first_name”
value=” < ?php echo htmlspecialchars($_POST[‘first_name’]);? > ”/ >
< input type=”hidden” name=”last_name”
value=” < ?php echo htmlspecialchars($_POST[‘last_name’]);? > ”/ >
< input type=”hidden” name=”address_1”
value=” < ?php echo htmlspecialchars($_POST[‘address_1’]);? > ”/ >
< input type=”hidden” name=”address_2”
value=” < ?php echo htmlspecialchars($_POST[‘address_2’]);? > ”/ >
< input type=”hidden” name=”city”
value=” < ?php echo htmlspecialchars($_POST[‘city’]);? > ”/ >
< input type=”hidden” name=”state”
Trang 7value=” < ?php echo htmlspecialchars($_POST[‘state’]);? > ”/ >
< input type=”hidden” name=”zip_code”
value=” < ?php echo htmlspecialchars($_POST[‘zip_code’]);? > ”/ >
< input type=”hidden” name=”phone”
value=” < ?php echo htmlspecialchars($_POST[‘phone’]);? > ”/ >
< input type=”hidden” name=”email”
value=” < ?php echo htmlspecialchars($_POST[‘email’]);? > ”/ >
< input type=”hidden” name=”shipping_first_name”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_first_name’]);? > ”/ >
< input type=”hidden” name=”shipping_last_name”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_last_name’]);? > ”/ >
< input type=”hidden” name=”shipping_address_1”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_address_1’]);? > ”/ >
< input type=”hidden” name=”shipping_address_2”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_address_2’]);? > ”/ >
< input type=”hidden” name=”shipping_city”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_city’]);? > ”/ >
< input type=”hidden” name=”shipping_state”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_state’]);? > ”/ >
< input type=”hidden” name=”shipping_zip_code”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_zip_code’]);? > ”/ >
< input type=”hidden” name=”shipping_phone”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_phone’]);? > ”/ >
< input type=”hidden” name=”shipping_email”
value=” < ?php echo htmlspecialchars($_POST[‘shipping_email’]);? > ”/ >
/div >
< /form >
The ecomm_checkout3.php script contains the most complex logic of the three checkout scripts, but you will find it is understandable if you patiently work your way through it The first major task is to assign the incoming data and some other important information (such as the current timestamp and the user ’ s session ID) to the variables that will be used throughout the script
$now = date(‘Y-m-d H:i:s’);
Trang 8$shipping_state = $_POST[‘shipping_state’];
$shipping_zip_code = $_POST[‘shipping_zip_code’];
$shipping_phone = $_POST[‘shipping_phone’];
$shipping_email = $_POST[‘shipping_email’];
Then you need to retrieve the customer ’ s ID from the ecomm_customers database In the case of an existing
customer, the ID can be retrieved with a SELECT statement If the customer is new, then he or she will not
have an ID already stored in the database, so the information needs to be added and a new ID generated
first_name = “’ mysql_real_escape_string($first_name, $db) ‘” AND
last_name = “’ mysql_real_escape_string($last_name, $db) ‘” AND
address_1 = “’ mysql_real_escape_string($address_1, $db) ‘” AND
address_2 = “’ mysql_real_escape_string($address_2, $db) ‘” AND
city = “’ mysql_real_escape_string($city, $db) ‘” AND
state = “’ mysql_real_escape_string($state, $db) ‘” AND
zip_code = “’ mysql_real_escape_string($zip_code, $db) ‘” AND
phone = “’ mysql_real_escape_string($phone, $db) ‘” AND
$query = ‘INSERT INTO ecomm_customers
(customer_id, first_name, last_name, address_1, address_2, city,
state, zip_code, phone, email)
With the customer ’ s valid ID now known, you begin the process of actually storing the order in the
database First, you insert the shipping information into the ecomm_orders table This creates the record and
generates the order ’ s ID, which you need to transfer the shopping cart ’ s contents into the ecomm_order_
details table You come back later to insert the cost values after you transfer the order details
Trang 9$query = ‘INSERT into ecomm_orders (order_id, order_date, customer_id, cost_subtotal, cost_total, shipping_first_name, shipping_last_name, shipping_address_1, shipping_address_2, shipping_city, shipping_state, shipping_zip_code, shipping_phone, shipping_email)
VALUES (NULL, “’ $now ‘”, ‘ $customer_id ‘, 0.00,
0.00, “’ mysql_real_escape_string($shipping_first_name, $db) ‘”, “’ mysql_real_escape_string($shipping_last_name, $db) ‘”, “’ mysql_real_escape_string($shipping_address_1, $db) ‘”, “’ mysql_real_escape_string($shipping_address_2, $db) ‘”, “’ mysql_real_escape_string($shipping_city, $db) ‘”, “’ mysql_real_escape_string($shipping_state, $db) ‘”, “’ mysql_real_escape_string($shipping_zip_code, $db) ‘”, “’ mysql_real_escape_string($shipping_phone, $db) ‘”, “’ mysql_real_escape_string($shipping_email, $db) ‘”)’;
‘ $order_id ‘, qty, product_codeFROM
ecomm_temp_cartWHERE
session = “’ $session ‘”’;
mysql_query($query, $db) or (mysql_error($db));
Instead of returning the information retrieved with the SELECT statement to PHP, the script passes the values directly into an INSERT statement and adds them to the table You can add a clause after the SELECT portion of the statement to instruct MySQL how to handle cases where a duplicate value might
be inserted into a column that requires all unique values (a primary key, for example), though that clause
is not necessary for your purposes here The syntax for an INSERT SELECT statement is:
INSERT [IGNORE] INTO tbl_name [(col_name, )]
SELECT
[ ON DUPLICATE KEY UPDATE col_name=expr, ]
After the products have been transferred from the ecomm_temp_cart table to the ecomm_order_
details table, they are removed from ecomm_temp_cart
$query = ‘DELETE FROM ecomm_temp_cart WHERE session = “’ $session ‘”’;
mysql_query($query, $db) or (mysql_error($db));
Trang 10The product information is now stored permanently in the details table and associated with the
appropriate order You now need to determine the cost of the purchase and then go back to update the
record in ecomm_orders with that information MySQL ’ s SUM() function adds the values of a column
together and is used to determine the purchase subtotal
For the sake of simplicity, we just use 25% of the subtotal as the cost of shipping, and 10% as the tax rate
Your values would be different, depending on your delivery arrangements and the municipality in
which you live
$cost_shipping = round($cost_subtotal * 0.25, 2);
$cost_tax = round($cost_subtotal * 0.1, 2);
$cost_total = $cost_subtotal + $cost_shipping + $cost_tax;
The order record in the ecomm_orders table is then updated with the order ’ s costs
$query = ‘UPDATE ecomm_orders
$headers[] = ‘Content-type: text/html; charset=”iso-8859-1”’;
$headers[] = ‘Content-Transfer-Encoding: 7bit’;
$headers[] = ‘From: < store@example.com >
$headers[] = ‘Bcc: < store@example.com >
mail($email, “Order Confirmation”, $html_head $html_body,
join(“\r\n”, $headers));
Trang 11E - Commerce, Any Way You Slice It
As we mentioned before, you can integrate e - commerce into your site the right way, or you can do it the wrong way To prevent yourself from looking like a complete idiot and virtually ensuring the failure of your venture into e - commerce, we highly recommend doing things the right way! Good word of mouth travels slowly, but we all know how quickly bad word of mouth spreads Also, with so many millions of web sites out there competing for consumers ’ attention, you undoubtedly want to elevate yours above the rest
Here are a few things to remember about some of the more challenging characteristics of your potential customers:
Your customers are impatient They don ’ t want to have to wait for your pages to load or for
answers to their questions They are busy people, just like you, and if they don ’ t find what they need right away, they will leave your site and go somewhere else
Your customers are distrustful Who wants their personal information strewn about all over the
web? You certainly don ’ t, and your customers don ’ t either They don ’ t want their credit card number to be used by every geek in your office, and they don ’ t want to give you tons of money and never see the product they purchased They don ’ t want to order from you one week and have you go bankrupt the next
Your customers want a lot for a little In this age of web site competition, when people can
compare prices on virtually any product with just a few mouse clicks, customers are striving to get the best deal they can But they also appreciate the value - added services of a high - quality web site
Your customers are generally lazy They don ’ t want to have to put any effort into finding the
right product on your site or figuring out what you ’ re trying to say or what your policies are
They don ’ t want to work at trying to get the checkout process to work, and they don ’ t want to have to filter through pages and pages of text to glean information Make things clear and easy
to find
Your customers aren ’ t very forgiving You basically have one chance to make a good first
impression on your customers Nothing can eliminate a sale (and future sales for that matter) faster than a bad experience Whether it is something minor such as spelling mistakes and broken images on your site or something major such as selling faulty merchandise, your customers are likely to remember something bad a lot longer than something good They will also be more likely to share a bad experience than a good one
Your customers may not be as technically savvy as you are Yes, there are actually people out
there who still use dial - up with 56K There are people out there who still use 14 - inch monitors, and there are people out there who have never made an online purchase in their lives
Remember these people, and don ’ t leave them behind totally when designing your site If you
do, you are alienating a huge percentage of the population
Don ’ t worry: Satisfying e - commerce customers is not hard, but a little effort can really go a long way
We ’ ve included some general guidelines to follow After reading them, you may think, “ Well, duh, no kidding, ” but you ’ d be surprised at how many big, well - known companies don ’ t follow them
Trang 12Information Is Everything
Your customers have to get as much information as possible about your product, because they can ’ t
actually see, feel, touch, or smell what you have to offer Your site is your window to your customers,
and they have to depend on what you ’ re telling them to make their purchasing decision Whatever
blanks you leave in your product description, policies, company history, or checkout process will have to
be filled in by the customer ’ s imagination While that may be good in certain circumstances, you do not
want your customers to make incorrect assumptions that leave them dissatisfied after the fact, or for
their uncertainty to prevent the sale altogether
Besides textual information, graphics are a very important part of the sale There is a fine balance
between adding too many graphics to your site, which causes your potential patrons to wait longer than
they need to, and providing enough high - quality pictures so they can actually see what they ’ re getting
Importance of Trust
Let ’ s talk for a minute about trust over the web We all know that most of the proclaimed 14 - year - old
females in those online chat rooms are really 40 - year - old guys sitting in their living rooms Things are
not always as they seem in the online world, and because of that, as an e - commerce retailer, you are at a
disadvantage over those with a physical storefront and salespeople And then there ’ s the old saying
“ caveat emptor ” ( “ buyer beware ” ), which goes along with any purchase/sales transaction Trust must be
established, and it certainly is an uphill battle If you ’ re an established business already and you have
spent years building product or brand - name recognition, don ’ t think that switching to e - commerce will
be so easy Yes, if your business has an established reputation, you may have an easier time than some
unknown entity, like “ Joe ’ s House of Beauty, ” but people still want to know what they ’ re getting and to
be assured that they ’ re not going to get ripped off
Privacy Policy
Users want to know that their personal information will not be sold and they won ’ t end up on 47 spam
e - mail lists They also want to make sure they won ’ t be on an annoying telemarketing phone list or
receive junk snail mail The only way they can be assured that this won ’ t happen is if you provide a clear
and concise privacy policy in an easy - to - find place on your site
Return Policy
Returns are a sometimes overlooked part of a company ’ s e - commerce venture There have to be
processes in place for accepting returns and shipping out replacement merchandise or issuing credits in
exchange Your users need to know what your return policy is, what your requirements are for accepting
returns, and how returns will be handled once they reach your warehouse (or basement)
If you are a relatively or completely unknown entity, you may want to consider providing a 100 percent
money back guarantee or something similar, to try to build trust with your potential customers You may
get burned once or twice on this, and it may require more work from you, but overall it can be a very
beneficial asset to you, especially if your customers are riding the fence on a potential purchase It also
motivates you to provide the best product or service you can, because you obviously don ’ t want to lose
100 percent of a sale!
Trang 13Whatever you decide, you should think long and hard about how you want to handle returned merchandise and then make sure your customers understand your decisions, in order to avoid potentially messy misunderstandings later on
Warm Bodies
In this age of technology, sometimes it ’ s nice just to talk to an actual living, breathing person who can answer your questions or help you find what you are looking for If you can manage this in your e - commerce environment, it is another great feature that will undoubtedly pay for itself in those “ on the fence ” purchasing decisions You can provide personal customer service in a few ways:
Give your customers a phone number (preferably a toll - free number) where they can contact your customer service staff (or just you, if you ’ re a one - person show)
Offer online customer service chat for your customers, where you can address customer questions or concerns without having to pay someone to wait for the phone to ring
Provide a customer service e - mail address for questions and problems Although this isn ’ t the optimal solution, because many people don ’ t want to wait for answers to their questions, at least this gives customers an outlet to vent their frustrations and then move on to something else
It also gives you a chance to prepare a proper reply and respond accordingly
Secure Credit Card Processing
Nothing will make your customers feel better than knowing their credit card information is safe and won ’ t get stolen along the way Make sure you are using a secure encryption method to transfer sensitive information, such as SSL certificates, a commonly used standard security technology for establishing an encrypted link between a web server and a browser This technology will make sure your customers understand how safe their transaction and personal information is It ’ s a good idea not to get too technical; just explain the security process in layman ’ s terms
If it ’ s possible, it ’ s a good idea to have a third party such as VeriSign verify that your site is secure, and prominently display its seal somewhere on your site
Professional Look
You want to make sure your e - commerce site doesn ’ t look amateurish and that it appears as professional
as possible A professional appearance is oftentimes equated with credibility in the minds of your customers, and it helps to build that elusive trusting relationship
Here are some ways to improve the look of your site:
Spend some time viewing other e - commerce sites What do you personally like about them?
What don ’ t you like? By emulating the big guys, you can look big, too
Invest in a few web site design books, or do some online research Numerous articles and books have been written on the topic, and you may as well not reinvent the wheel
Trang 14If you use a template of some sort, please, please, please do yourself a favor and make sure you
remove all generic instances We ’ ve seen sites with a title bar that reads “ Insert Description
Here ” This is not a good look … trust us
Spell check your document Spell checkers are available in nearly all text editors, so spelling
mistakes are pretty much unacceptable and can really undermine your professional look
Easy Navigation
You want to make sure your customers are able to move around your site and find what they need
Remember the rule from earlier in this section: They do not want to work too hard Make it easy, or they
will lose interest and go somewhere else
Common Links
Make sure you have clear links to every area of your site, and put the common links near the top where
they can be seen easily Common links include a customer ’ s shopping cart, customer service, and user
login
Search Function
You should give your customers a way to easily find what they ’ re looking for An accurate and quick
search engine is essential to accomplish this There are many ways to add this feature to your site, either
through coding it by hand in PHP or hooking up with third - party software Another way to improve
your search engine is to make sure you include misspellings and not - so - common terms, to give your
customers the best results possible
Typical Design
It ’ s been long enough now that most people are accustomed to seeing navigation links either at the top
or to the left side of a page By keeping with this general scheme, you can ensure that your customers
will know where to look to find what they need
Competitive Pricing
If you are selling items that are available from other sources, it ’ s important to remember that your store
can easily be compared with numerous other stores selling the same thing If your prices are way out of
line, your customers will get a good chuckle and then promptly click back to their Google search Do
your research, and make sure you are in line with similar products being sold on the web Not all
customers base their decision solely on price, but they definitely don ’ t want to be taken for a ride, unless
you have a Lamborghini Diablo, and that ’ s a different story
Appropriate Merchandise
Only a handful of stores on the web can get away with carrying a wide range of unrelated products,
and — no offense — chances are you aren ’ t one of them Be sure you are carrying items that are related to
your overall site and to each other, or you will confuse your customers and detract from your look and focus
❑
❑
Trang 15Timely Delivery
In this world of “ overnight this ” and “ immediately download that, ” it is no longer acceptable to ask for six to eight weeks to deliver your merchandise to your customers The only exception is if you are creating something custom made, or if your customers are preordering something that hasn ’ t been officially released yet The typical lead time for standard products to ship to a customer is roughly two to three business days If you can do better than that, your customers will be happy, and if not, you need to make sure your customers realize it will take longer, and give them an explanation
It is also important to provide numerous shipping options to your customers and let them decide how quickly they need your products and how much they are willing to spend to get them faster
Communication
Because you are isolated from your customers, communication is essential to building strong relationships Your customers want to know that you received their order, when the order is ready to ship, and when it ships They appreciate getting a tracking number so they can see where their package is every step of the way Some companies even track each outgoing package and let their customers know when they think the package has been delivered, in case there are any misunderstandings All of this can
be communicated via e - mail Your customers will definitely appreciate being kept in the loop and knowing that their order has not been lost somewhere along the order fulfillment and delivery chain
Customer Feedback
The online world presents an interesting dilemma for e - commerce retailers, in that you must operate your store in a bubble You can ’ t tell what your customers are thinking or how they react to your site
You only know you ’ re relatively successful if you have sales, and relatively unsuccessful if you don ’ t
Figuring out which of our rules you ’ re breaking can be a tricky endeavor That ’ s when your customer feedback can make or break you
You always want to give your customers an outlet to express their concerns or problems, and it can give you a warm fuzzy feeling to get some positive feedback once in a while To encourage your customers to provide you with feedback, you should do two things:
Give them an incentive to complete a survey or provide some sort of feedback Free shipping, a discount on their next order, or a special gift of some sort are a few good possibilities
Make it easy for your customers to complete a survey, but make sure it provides you with valuable feedback Don ’ t just ask for their comments; ask them to rate certain areas of your site Also, don ’ t give customers 100 questions; keep it to a maximum of 20 After that, people lose interest, and the special gift isn ’ t worth it
By sticking to the preceding guidelines and advice, you will increase the quality and quantity of your customer feedback and increase your ability to tap into one of your most valuable resources
❑
❑