Practical PHP and MySQLBuilding Eight Dynamic Web Applications phần 5

Showcart () chức năng có chứa một liên kết để , trong đó bạn có thể loại bỏ một mục khỏi giỏ hàng. Bằng cách nhấn vào liên kết, mục được lấy ra từ bảng orderitems, và tổng giá trong bảng đơn đặt hàng được cập nhật. Tạo và bắt đầu thêm các mã: | CHAPTER 6 Creating a Shopping Cart 195 Deleting Items The showcart function contains a link to in which you can remove an item from the shopping cart. By clicking the link the item is removed from the orderitems table and the total price in the orders table is updated. Create and begin adding the code php require require require validid pf_validate_number _GET id redirect config_basedir . itemsql SELECT FROM orderitems WHERE id . _GET id . itemres mysql_query itemsql numrows mysql_num_rows itemres if numrows 0 header Location . config_basedir . itemrow mysql_fetch_assoc itemres In this code the query pulls the item from the orderitems table and the number of rows returned is checked. This check prevents someone modifying the URL and adding id 73 if there is no item with an id of 73. If no rows are returned a header redirect jumps to . If a row is returned the script continues itemrow mysql_fetch_assoc itemres prodsql SELECT price FROM products WHERE id . itemrow product_id . prodres mysql_query prodsql prodrow mysql_fetch_assoc prodres sql DELETE FROM orderitems WHERE id . _GET id mysql_query sql In this block the price of the product is selected first and then a separate query removes the item from orderitems. Update the orders table with the new total price 196 Practical PHP and MySQL mysql_query sql totalprice prodrow price itemrow quantity updsql UPDATE orders SET total total - . totalprice . WHERE id . _SESsIoN SESS_ORDERNUM . mysql_query updres header Location . config_basedir . With the cart summary function and pages complete your browser should show something similar to the page shown in Figure 6-6. FIGURE 6-6 The shopping cart summary displays a current list of items and the ability to remove them. Checking It Out After the user has finished adding items to his shopping cart the checkout process can begin. This process involves two steps .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.