Sunday, March 8, 2020

Advanced Shopping Cart using PHP, an Apache server and an SQL database


For this project I created an advanced shopping cart using PHP, HTML and a backend Apache server with an SQL database. It pulls the data from the database in realtime so that it's easier to manage inventory and product updates. 

The first thing a shopping site needs is items to sell so that is the first thing I created. This was simple enough. I just needed an image, a product description, product name and a shopping cart button so it can be added to a cart.



Now that I knew what items I would be selling and what the product details were I was able to create a database. Rather than do this manually, I did it with PHP so that in the future updates can be done with code adjustments rather than manually doing the whole process over.



That code above creates the database. As you can see I created a table with 4 columns: product_name, product_price, product_image, product_id. The same process can just be extended if the specific product has more variations like colors, sizes or variety of materials.


This is the initial database that is created.


And here are the items I am inserting into the database.


And here is how I added the items to the shopping cart. I start a new session for each customer and then store the session variables within the session.


So now here I have the HTML page pulling all the inventory item information directly from the database to the shopping site and I have cart information going directly into the database. I have at this point already included a header php file which links to a shopping cart view where specific quantities and order totals can be adjusted.

                   

Here is the view of the shopping cart area for once products have been selected and the customer is deciding exactly what they want their total purchase to be with shipping.


And here is where I am storing the session data which includes the items being added or removed and keeps a running total of everything within session data.

                         


And here I have a simple price details table that I can feed into my inventory system to generate a final invoice and a purchase order for my warehouse to ship the items. So here we have a simple example that shows the power of being able to use PHP to link SQL data directly to create an advanced web shopping cart that can be scaled.



No comments:

Post a Comment

Automated Exploitation of a Bluetooth vulnerability that leads to 0-click code execution

This blog post covers an interesting vulnerability that was just discovered earlier this year and an open source free tool that was created ...