php SESSION application example (shopping cart)
SESSION Application Example
Login example: (Please note that you must type it yourself, no CV method)
First, look at the results chart to stimulate students' desire to write. The login page is as follows:
Explain what the problem is. Next, implement it yourself.
First database information:
Create a new database named login, and then create a user table. The structure of the table is as follows:
welcome.php Here we use the information in the session, instead of bringing parameters in the URL like cookies.
welcome,Example of shopping cart: (Please note that you must type it yourself, do not CV Dafa)
Database information: Create a database named test. There is a shop table in the library. The table structure is as follows:
Start Let’s code!goodsList.php This is the product display page. The rendering is as follows:
Explain that if it is the first time to purchase an item, add the product information to the shopping cart and calculate the total price. If it is purchased again, Click to purchase, the quantity of purchased items will be increased by 1, and the total price will be recalculated. View the shopping cart link to go to the shopping cart page.
购买"; echo 'buy.php This page completes the purchase function and then jumps to the product list again. The main purpose is to process the purchase of goods in the session.
'; } ?> 查看购物车
shoppingCart.php This page displays the products, prices, total price and other information in the shopping cart.
The renderings are as follows:
'; foreach ($goods as $value) { echo $value['name'] . ' 价格 ' . $value['price'] . ' 数量 ' . $value['number'] . 'The shopping cart example is completed. Do you feel a sense of accomplishment after completing it yourself? ! you're good! !
'; } echo '总价:' . $_SESSION['totalPrice'] . '
'; ?> 返回商品列表