Create Shopping Cart Using PHP and Mysql

preview_player
Показать описание
Create Shopping Cart Using PHP and Mysql
Hello Friends,
In this Video We are creating Simple Php Cart Tutorial.

Download Sorce File :)

Create new shopping cart project and add four product images.
Create new database Product detail,
create a new table product and add 4 column id, pname , images and price.
now we are inserting our product details in our table we are adding four product in table.

before we start make sure that you had subscribe to daily tuition channel.
First Create a new php file with php extenstion.
We are using bootstrap framework with javascript library.
Now we are import google font in for better font family.
Copy google font url and paste in style tag in our file.
Now create new php session on top of the page.
And create a new variable and assign database name to that variable.
Now create Database connection and pass four parameter .
Host name, username, password and database name.

Now create sql query to fetch data from our table.

Execute mysql query with two parameter connection and Query string.
Now we are check if product table number of rows is greater than 0.

In while condition we are fetch array and store in $row variable in array format.
Now we are display dynamic images so we are adding php tag in source of image tag.

This way we are display Dynamic image on our page.
Now I want to display product name php $row["pname"]
in this way we are display product name from sql table.
Do the same to display price also.
Now add input type text to add quantity of product
Now create submit button input type="submit"
Add css style to division tag of product class.
Now create a table to display product details.
Create a php code to calculate total amount of product.
So first we are check that our cart session is empty or not if it is not empty

To display product information in key and value pairs. This way we can access all values of session cart.
Now I want to display item name so is have use echo
To display item name from our cart session
Now I want to display item quantity and price so I do that same as I do this before.
After this we want to calculate price of product base on quanitity.
So we are adding item quantity divide by item price.
After this we want to remove item from cart so we are add

to access the id of product.
Now we want to calculate total price of product so we add

After this create new row with colspan three and align this to right.
Now display total amount of your product with

after this create new css style to table table head and table data.
And also style up shopping cart details titile.
So now run script
We are getting error in the line no 137
So make sure that you are compete all curly brackets.
Here we miss one curly bracket so we add this to remove this error and again run this project.
Now we cannot see the image because we only specify the name of our image not the absolute path of our image so I have move this image from image folder to our root path. And delete image folder.
Now we are creating a php code top of the page

Then check that our session cart variable value is set or not with isset function.
Create new variable item array id with two parameters.

Now add in array function to check whether a value exists or not.
Create item array variable
Now after this assign item array value to session cart to count index we already specify session cart to count variable.

After this check if session cart variable is not set then the isset execute else block.

Now we will run our project but we find that table is not display properly so let’s find out what is the problem
In this code we missing the table tag so we will insert table tag with table and table bordered.
Then we are check that if get action is equal to delete if it is true then further code is execute.
Now create a for each to access the value of session cart variable.
After that check that if product if is equal to get id.
If it is true then execute further code and unset session cart variable.
Now we cannot see product price and name so let’s find out what is the problem.
We are missing the echo function in the h5 tag in design section.

Add laptop bag one quantity and vivo v5 with three quantity.
Iphone 6 with 2 quantity and Phillips trimmer with one quantity.
And at the bottom you will see the total price is calculated.
Now we are remove vivo v5 item from the cart and it was removed.
At again remove iphone 6 and you will see the difference in total price is reduced because we was removed one product.

so if you have any question or any opinion please comment on my video and share this video to you friends. If you have any other question you can chat with me in channel discussion. You can follow me on Facebook Page.

Thank You...!
Рекомендации по теме
Комментарии
Автор

I am developing a restaurant ordering system for my college class final project, I was stuck at this step and after watching and reading God knows how many tutorials, this saved me! thanks :)

julianasarmo
Автор

Thank you. You're the best. In one tutorial, lasting less than half-an-hour, you beautifully explained the code for shopping cart using PHP. I was afraid to touch this subject until now.

narayananseshagirirao
Автор

you can never understand how greatfull i am after strugling so much at university and fi, ally findin your channel

yeyouhd
Автор

Thank u so much..This helped me lot in project

usernotfound
Автор

YOU DID IT!! Finally after watching 10 DIFFERENT VIDEOS, your video was the one that actually got the images to show up. THANK YOU SO MUCH. PLEASE TAKE MY LIKE AND SUBSCRIPTION ♥♥♥♥♥♥

jimmychoose
Автор

Nice sir make video of invoice gst tax

sasaram
Автор

Amazing Sir!! Thank you for sharing this

yehezkielputragalang
Автор

So nice
Please make full ecommerce website.

malakfarhan
Автор

Hi . Your video make lots of sense and make it easy . Can You please make another video of cart page when user logged in and cart data stored under individual users ? Like we know that when logged in a site and do add to cart and logout, if we logged in even after 1 year, we can see that what we add in cart . Thats mean data stored in DBMS. By session or cookies - for only guest users . So if you can make this video, it will be great help . Thanks

LearnwithKamrulHasan
Автор

Thank you so much. This helped me a lot. :)

asthanihar
Автор

This channel should get 1M subscribers

rumanzahid
Автор

BEST OF THE BEST MAKE ONTHER ONE FOR ACCOUNTS

denismurithi
Автор

Great tut. I am wondering where is that $_SESSION["cart"] variable come from if it is not defined previously. Thanks a lot!

Dzinuljak
Автор

CREATE TABLE product(
id INT AUTO_INCREMENT PRIMARY KEY,
pname VARCHAR(255),
image VARCHAR(255),
price DOUBLE
);

k.chriscaldwell
Автор

It was so nice working on this video, this was exactly what I wanted best tutorial in less time, also sorce code file was helpful for coding, because code was not that visible on mobile screen, but with the help of ur explanation and code material really helped me alot in my project, thank you sir.

AshwiniYogeshHendre.
Автор

INSERT INTO product(pname, image, price) VALUES
("Laptop Bag", "bag2.png", 15.00),
("Vivo v5", "vivo-x20.png", 232.92),
("Phillips Trimmers", "Philips_Trimmers.png", 24.00),
("iPhone 6", "apple-iphone-6-space-grey-front.png", 399.26);

k.chriscaldwell
Автор

very beautiful tutorial....would you please include the checkout capability...please please

nielbatman
Автор

Thanks a lot for the tutorial)) but i have an issue... i have multiple pages with products and to show them all in one cart page not going to look nice...I wanna make the cart separate where u can add products from different pages and show them in a cart, like on most web-sites

kateiluk
Автор

I found out the reason. It is because after the 2nd-item was deleted, the array has not been sorted appropriately:

product_id -> 1, item_name -> iPhone 12, product_price -> 11500, item_quantity -> 1,


product_id -> 3, item_name -> XiaoMi T10, product_price -> 5600, item_quantity -> 1,

You can see the middle (2nd) row was left blank.

So, what is the best way to solve this please?

HongKong
Автор

Thanks for this helpfull video. Do you know how it's possible to set the number per product to 2, 3, 4, ... when you click on "add to cart" more times?

jb