Create Shopping Cart Using PHP and Mysql

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome to daily tuition in this video we are creating simple PHP carp tutorial create new shopping part project and add four product images [Music] [Music] insert new database name as product detail [Music] [Music] and insert a new table product and add four column end pn AME images price we are adding four product in our table first value is product name second is image source and third is product price make sure that your image file name is correct [Music] first we are adding product name laptop bag on the second parameter we insert laptop bag image on third parameter we insert value of laptop bag then we are adding product name vivo v5 on the second parameter we insert vivo v5 image on third parameter we insert value of vivo v5 then we are adding product name Philips trimmer on the second parameter we insert Philips trimmer image on third parameter we insert value of Philips trimmer [Music] then we are adding product name iPhone 6 on the second parameter we insert our iPhone 6 image on third parameter we insert value of iPhone 6 now we are inserting our product details in our table we are adding four product in table make sure you are using absolute path of your images before we start make sure that you had subscribed to Daly tuition channel first create a new PHP file with PHP extension [Music] [Music] we are using bootstrap framework with JavaScript library [Music] coppy bootstrap CD and in your car dot PHP file in head section [Music] now we are import Google font in for better font family [Music] coppy google font URL and paste in style tag in our file [Music] [Music] [Music] now create new PHP session on top of the page and create a new variable and assigned database name to that variable now create database connection and pass for parameter hostname username password and database name Dalek on equals my's CLE underscore connect localhost root dollar database underscore name [Music] [Music] now create SQL query to fetch data from our table dollar query equals select asterisk from product order by a descending order [Music] execute my SQL query with two parameter connection and query string [Music] now we a check if product table number of rows is greater than 0 if my split underscore name underscore rows dollar result greater than 0 then condition is true and run further code in while condition we are fetch array and store in dollar row variable in array format [Music] [Music] we are at action equals car dot php' question mark action equals that and it equals less than PHP echo dollar row it to access it within page [Music] now we are displayed dynamic images so we are adding PHP tagging source of image tag IMG SRC PHP echo dollar Rho image this way we are display dynamic image in our page now I want to display product name PHP dollar o P n AME in this way we are display product name from SQL table [Music] to the same to display price also [Music] now add input type text to add quantity of product [Music] [Music] create input type hidden' name hidden name and input type equals hidden name hidden price for future use you [Music] now create submit button input' type submit' [Music] you [Music] add CSS style to division tag of product class [Music] [Music] [Music] [Music] [Music] [Music] now create a table to display product details [Music] you [Music] [Music] [Music] [Music] create a PHP code to calculate total amount of product so first we are check that our card session is empty and not if it is not empty [Music] then create for each dollar underscore session cart as dollar key equals greater than dollar value 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 as have you Seco dollar value item name to display item name from our cart session [Music] now I want to display item quantity and price so I do that same as I do this before [Music] [Music] [Music] you [Music] you after this we want to calculate price of products based on quantity so we are adding item quantity divided by item price [Music] [Music] after this we want to remove item from cart so we are add action equals delete and in equals PHP echo dollar value product it to access the init of product [Music] [Music] now we want to calculate total price of products are weird dollar total equals total plus value item quantity divided by value product price [Music] after this create new row with colspan three and aligned this two right [Music] now display total amount of your product with a go number format dollar total to [Music] [Music] [Music] after this create a new CSS style to table th and table TD and also style up shopping card details title [Music] [Music] [Music] [Music] so now run project we are getting error in the line number 137 so make sure that you would compete all curly brackets here we miss one curly brackets 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 moved this image from image folder to our route path [Music] and delete image folder [Music] [Music] you now we are creating a PHP code top of the page first check the decid submit button then check that our session card variable value is set a not with isset function [Music] create new variable item array it with two parameters dollar item array it equals array column dollar session card productive now add an array function to check whether a value exists or not we have passed two parameter to an array function first get it and item a rated to check whether it is exists of not [Music] now create new variable and assign session card to count variable dollar count equals count session card [Music] create item array variable dollar item underscore array equals array product it equals greater than dollar getpid item name equals greater than dollar posed hidden name product price equals greater than dollar posts hidden price [Music] item quantity equals greater than dollar posed quantity now after this assign I to Marais valued accession card to count index we already specify session card to count variable [Music] now redirect our page with echo window.location equals cart dot PHP [Music] if in a Rea function find the same it then we want to display product is already added in the cart message and redirect page to window location equals cart dot PHP page after this check if session cart variable is not said then Diaz sat executes else clock and create new variable item or a dollar item underscore array equals array this code is executed if session car session is not set now assign item array to session cart in zero index dollar session car 0 equals dollar item underscore array at the end of the code now we will run our project but we find that table is not display properly so let us find out what is the problem in this code we missing the table tag so we will insert table tag with table and table boarded [Music] now we will run project and it will work fine after this we want to make remove item codes so we will use if is set action to check if user click on the remove item and return value 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 the check that if product if is equal to get it if it is true then execute further code and unsession cart variable [Music] and using echo create JavaScript alert tag to display product has been removed message [Music] and then redirect page to window.location equals car dot php' within javascript code run project now we cannot see product price and name so let us find out what is the problem we are missing the echo function in the h5 tag in design section run project and now we will see the product name and product price now let us see how it s work add laptop bag 1 quantity and vivo v5 with 3 quantity [Music] iPhone 6 with two quantity and Philips 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'll see the difference in total price is reduced because we was removed one product if you have any question please ask me in video comment section liked this video and subscribe to this channel thank you
Info
Channel: Daily Tuition
Views: 185,745
Rating: undefined out of 5
Keywords: Create Shopping Cart Using PHP and Mysql, php shopping cart session, create shopping cart php mysql tutorial, how to create online shopping website in php, how to create shopping cart using php, php shopping cart tutorial using session, how to create php shopping cart tutorial using session variable, create shopping cart, create shopping cart php mysqli, php and mysqli tutorials, php tutoiral, php cart tutorial sample, add to cart php tutorial
Id: IO5ezsURqyg
Channel Id: undefined
Length: 28min 2sec (1682 seconds)
Published: Thu Nov 30 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.