New Page 1
Completeness of PHP commands, if a user add items to your vehicle is ready, it usually goes to a sale. Fill orders, several steps are necessary to allow verification that sufficient stocks are available, are sold to complete your purchase, conversion of the basket in order, and after deduction of wines from inventory. These tasks require locking the database and sample handling moderately complex query. The script. 3 shown in Example 12-1, performs this task. The script works as follows: It checks whether the user is logged on and the car has a content. These tests should never be missed, as bodies “Buy” button only appears when the user is viewing the car is connected, and car content. If the test fails, an error is logged, and the script redirects to the calling script. In-stock items, orders and tables are locked for writing and has blocked the use of tables and Customer are for reading. In-stock items, orders and tables are all updated to the procurement process, and they should be blocked because the inventory control to ensure that sufficient quantities of wine are available and made days later. Without barriers, it is possible to buy the wine for another user, while the script is executed, which is sold in most wine is in stock. This debate is an example of parallel play dirty in Chapter 6 and should be locks to prevent the problem. Each item in the basket are then processed and inventory is checked to ensure that the wines available are sufficient. If any wine is the count () lines appropriate directory is invalid, an error is recorded. Similar wine, but unless the user wants available, the sum () of on_hand whole line is less than user error Shopping cart Qty will also be recorded. If an error occurs is, the script also updates the user’s basket, so the quantity (amount) of wine in the basket of the user matches the quantity that is on_hand. In the case of an error by using the script showWine () to show the user details of wine. This function opens its own connection to the DBMS, so that the wine_variety wine, wine and table grape_variety should not be locked for read in order. If inventory controls to be successful, the script to convert cart to the user to place an order by the customer. This process is simple: determine the loginUsername cust_id variable with the function getCustomerID (). Find the maximum for this client order_id. Update commands and sections of the line instead of -1 cust_id cust_id with the client and the order_id order_id with the next available for that client. After the database is updated, the cart is empty session_unregister () to delete the session variables order_no. After the order completed and verified the inventory, the script ends the ordering process by reducing inventories. This may simply never fail, since all the required tables are locked, and you have verified that sufficient quantities are available. The process is similar to the review of the investigation: They go through each point and for anyone to update the inventory. Inventories are handled by the oldest to newest. Consider an example where the user wants to buy 24 bottles of wine. There are two directories of this wine: the first, with 13 bottles and was registered in May 2000, the second with 25 bottles and was admitted in September 2001. To respond to the command as the oldest inventory of 13 bottles emptied and removed, and the second part is reduced from 11 bottles. With the completion of this process, the tables are locked. If there are no errors, the script redirects to the maritime sector. 1 Script to confirm the order and sent cust_id and order_id as a method of GET parameters. If there are errors, the user is on the back page of the cart. Example 12-1. Order. 3 Acquisition of the user closes Php / / This script includes a buy / / It is expected that a basket and the / / user is include 'are registered. inc '; set_error_handler ( "errorHandler") / / restore the existing session session_start () / / Check if there is a car - it should never fail / / if the script is executed directly if (session_register ( "order_no")) (session_register ( "message"); $ message = "There are no products in your cart!" / / redirect the browser to return to the header page request ( "Location: $ HTTP_REFERER") exit; ) / / Check if the user is logged - this should / / never fail if the script is executed directly if (session_register ( "login Username")) (session_register ( "message"); $ message = "You login to conclude your order. "/ / redirect the browser to return to the header page request (" Location: $ HTTP_REFERER ") exit;;) / / Opens a connection to the DBMS if (($ connection = @ mysql_pconnect ($ hostname, $ username, $ password))) show error () if (mysql_select_db ($ databaseName, $ connection)) Error show () / / tables must be locked, to complete a purchase. / / We lock the other four tables / prevent / connection with another DBMS information wines / / $ query = 'LOCK TABLES inventory write, write prescriptions, article writing, reading create users, advertisers READ "/ / Lock the table if ((mysql_query ($ query, $ connection))) error show () / / Process each wine in the car and see if / / There is enough stock in the $ query =" SELECT * FROM Products WHERE cust_id = -1 and order_id = $ order_no ', / / Initialize an empty error message $ message = "" if (($ result = mysql_query ($ query, $ connection))) error show () / get / next wine to buy food (winesInCart $ = 0; $ winesInCart
“else $ message. = “Sorry, we did that. on_hand $ [" SUM (on_hand) "].” bottle “on the left. showWine (cartRow [$ winesInCart] [" wine_id "], NULL).” n ” / / update user set in the order_no / / amount available to match $ query = “UPDATE Products SET qty = ‘$. available.” WHERE cust_id = -1 AND order_id = $ item_id = “. cartRow [$ winesInCart] [ "item_id"] if ((mysql_query ($ query, $ connection))) ();)) ShowError / / for winesInCart mysql_num_rows $ <($ result); / / We have to consider s If there is enough wine / / available. / / If yes, then we will be in order. / / If not, we will send the user to change / / carts to buy the least / / amount of thinking. if (empty ($ message)) (/ / All ok - Nonsense! / / First, select your username and cust_id / / order_id the next available for that client. custID getCustomerID $ = $ (name of user login, NULL); $ query = "SELECT max (order_id) FROM orders WHERE cust_id = $ custid" row if (($ result = mysql_query ($ query, $ connection))) $ = mysql_fetch_array ($ result); show else error (); newOrder_no $ = $ row [ "max (order_id)"] + 1 / / Now order_id in the cust_id and shopping! $ query = "UPDATE orders SET cust_id = $ custid. order_id =". newOrder_no $. "WHERE order_id = $ order_no; if ((mysql_query ($ query, $ connection))) error show (); $ query =" UPDATE products SET cust_id = $ custid. order_id = ". $ newOrder_no." WHERE order_id = $ order_no "if ((mysql_query ($ query, $ connection))) error show () / / session_unregister officially empty your shopping cart (" order_no ") / / Now we need to take inventory. / / We do a basket of 'items at once. / / For all items that we know it is * / / insufficient stock, as we have previously discussed foreach ($ cartRow as $ currentRow) (/ / find the tracks for this wine selected by the older $ query = "inventory_id composed from on_hand wine_id WHERE =". $ currentRow [ "wine_id"]. "ORDER BY date_added" if (($ result = mysql_query ($ query, $ connection))) ShowError () / / If there are still bottles will be deducted while ($ currentRow [ "qty"]> 0) (/ / Get the next-oldest inventory $ row = @ mysql_fetch_array ($ result) / / Are he want more wine in this directory as / / the user if ($ row [ "on_hand"]> $ currentRow [ "qty"]) (/ / inventory reduction by the amount of the / / user ordered $ query = “SET Inventory Update = on_hand on_hand -”. $ currentRow [ "qty"]. “WHERE wine_id =”. $ currentRow [ "wine_id"]. “AND inventory_id =”. $ row [ "inventory_id"] / / The user no longer has sales / wine $ currentRow [ "qty"] = 0;) else (/ / Remove the inventory – we are / / The result of this user $ query = “DELETE FROM inventory WHERE wine_id = . $ currentRow [ "wine_id"]. “AND inventory_id =”. $ row [ "inventory_id"] / / This reduces inventory customer / / Required quantity of at least 1, but I / we need to make process inventory $ currentRow [ "qty"] -= $ row [ "on_hand"]) / / UPDATE or DELETE, the inventory if ((mysql_query ($ query, $ connection))) else ();))) $ error performance. = N
quantities in your basket. “Update #” / UNLOCK tables load $ query = “UNLOCK TABLES” if ((mysql_query ($ query, $ connection))) ShowError () / / Redirect to the email confirmation page / / If everything is ok / / (provision and custID orderID script) / / otherwise go to the shopping cart page and display a message if (empty ($ message)) (header ( “Location: eg. dispatch 1. php?”. “CustID = $ = $ custid & orderID newOrder_no “) exit;) else header (” Location: eg. shopping. php 2 More “);?> PHP Tutorial
Archive for March 27th, 2010
PHP-order completion
Author: adminMar 27
