Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Duke

Chapter 10 Checkout.php

Recommended Posts

RE: checkout.php...p 301 step17...just showing a work around that works at this stage of chp 10

could not get this line to return the  id...$r = mysqli_query($dbc, 'SELECT @cid'); as a result there is no value to store in  list($_SESSION['customer_id']) = mysqli_fetch_array($r);...(even reworked the stored procedure for add_customer..no luck

 

My work around:

 

I set $cid = mt_rand(100000,1000000000);

 

added customer_id column to customer's table....

changed the stored procedure=add_customer...to also  include customer_id...and....VALUE.... $cid

changed setting session to: $_SESSION['customer_id'] = $cid;

 

this seems to be working at this stage of chp 10...

Share this post


Link to post
Share on other sites

using the above work around....in chapter 11....

for view_orders.php script I changed the query to

 

$q =   'SELECT o.id, FORMAT(total/100, 2) AS total, c.customer_id AS cid,
        CONCAT(last_name, ",", first_name) AS name, city, state,zip,
        COUNT(oc.id) AS items FROM orders AS o
        LEFT OUTER JOIN order_contents AS oc ON
        (oc.order_id=o.id AND oc.ship_date IS NULL)
        JOIN customers AS c ON (o.customer_id = c.customer_id)
        JOIN transactions AS t ON (t.order_id=o.id AND t.response_code=1)
        GROUP BY o.id DESC';

 

for the view_order.php script I changed the query to

 

$q ='SELECT FORMAT(total/100, 2) AS total, FORMAT(shipping/100,2) AS shipping, credit_card_number, DATE_FORMAT(order_date, "%a %b %e, %Y at %h:%i%p") AS od, email, CONCAT(last_name, ", ", first_name) AS name, CONCAT_WS(" ", address1, address2, city, state, zip) AS address, phone, o.customer_id, CONCAT_WS(" - ", ncc.category, ncp.name) AS item, ncp.stock, quantity, FORMAT(price_per/100,2) AS price_per, DATE_FORMAT(ship_date, "%b %e, %Y") AS sd FROM orders AS o INNER JOIN customers AS c ON (o.customer_id = c.customer_id) INNER JOIN order_contents AS oc ON (oc.order_id = o.id) INNER JOIN non_coffee_products AS ncp ON (oc.product_id = ncp.id AND oc.product_type="goodies") INNER JOIN non_coffee_categories AS ncc ON (ncc.id = ncp.non_coffee_category_id) WHERE o.id=' .$order_id. '
UNION
SELECT FORMAT(total/100, 2), FORMAT(shipping/100,2), credit_card_number, DATE_FORMAT(order_date, "%a %b %e, %Y at %l:%i%p"), email, CONCAT(last_name, ", ", first_name), CONCAT_WS(" ", address1, address2, city, state, zip), phone, o.customer_id, CONCAT_WS(" - ", gc.category, s.size, sc.caf_decaf, sc.ground_whole) AS item, sc.stock, quantity, FORMAT(price_per/100,2), DATE_FORMAT(ship_date, "%b %e, %Y") FROM orders AS o INNER JOIN customers AS c ON (o.customer_id = c.customer_id) INNER JOIN order_contents AS oc ON (oc.order_id = o.id) INNER JOIN specific_coffees AS sc ON (oc.product_id = sc.id AND oc.product_type="coffee") INNER JOIN sizes AS s ON (s.id=sc.size_id) INNER JOIN general_coffees AS gc ON (gc.id=sc.general_coffee_id) WHERE o.id='.$order_id;  

 

..seems to work . I am going to check it more...just wanted to add above in case anyone uses mt_rand() for customer id

 

Thank you

 

Share this post


Link to post
Share on other sites

In keeping with what I am using in this topic.. in chapter 13 page 423.... I changed the query as follows(need to change in 2 places

 

originally............INNER JOIN customers AS c ON (o.customer_id = c.id) 

I changed to .....INNER JOIN customers AS c ON (o.customer_id = c.customer_id)

 

Thank you

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...