Create Simple Shopping Cart using PHP & MySql

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends in this video we are going to create simple shopping cart by using PHP programming with MySQL database in this example I will display product from database and each product we have given option to user can enter quantity and adding product to cart and all product details are stored in session if buyer not want to buy product then he can also remove product from shopping cart this is done by clear this session of that item from the cart and item will be removed from the shopping cart this is a very simple shopping in which I have only used PHP with MySQL database this is for beginner programmer who want to create simple shopping cart by using core PHP this is my task database and in this database I have one table product with four column like head name image and private product I have already inserted three product into this table I will fetch the Satyam data from this table and will display on webpage I have store product image in my working folder and get image from product table and display on webpage now friends I have moved to develop simple shopping cart by using PHP so I have start coding this is my index dot PHP page and in this page I've used bootstrap CSS framework with query JavaScript library on this page first I have right session start PHP function this function will start session on this page and linked pages after this I have made database connection so for this I have write connect variable is equal to miss CLE connect function with 4 parameter like host is equal to locale lost username is equal to root password is equal to root and database name is equal to test now I want the display product on webpage from database so I have write one query variable is equal to select star from table product to order by it with ascending order after this I want to execute this query so for this I have write one result variable is equal to miss CLE query function with two parameter like database connection string is equal to connector and SQL query which I have store in query variable this function will execute my SQL query and store into resolved variable now I want to check there is data and result variable or not for this I have write of statement with condition and in this condition I have right miss clean um rows function with parameter like resolved variable with greater than 0 this function returned the number of rows in query result and it is greater 0 or not if it is greater than 0 then I want to fetch all data so for this I have write while loop with open and close bracket and between bracket I have write row variable is equal to miss Klee fetch array with result variable this function fetches a result of Rome as an associative array and store into row variable and by using this row as reference and fetch all data and display on web page now I have moved to HTML code and while loop and first I have write open and close division tag with class named column D for which class at bootstrap library between this tag I have right open and close form tag with method post an action equal to index dot PHP question mark action is equal to ad and it is equal to dynamic ade of product which we have kept from product table for a dynamic it I have write a cout statement with row variable with column name it after this I want to display dynamic images from database so I have right image tag with sources equal to row variable with column name image this way we can display dynamic image from database after this I want the display name of product so for this I have right taco statement with row variable with column name name this will display product name on webpage after this I want to display price of product from database so for this I have right row variable with column name price this will display a price of product on webpage after this I have want to display on text box on web page in which user can enter how many quantity he want to add into shopping cart so for this I have write input type text with name is equal to quantity and default value is equal to one after this I want to add one hidden field and in this field I want to store the value of product name for future use so for this I have write input type hidden' with name is equal to hidden name and value is equal to open and close PHP tag in between tag I have write echo statement with row variable with column name like name after this I want add one more hidden fields' and in this fields I want to store price of product for this I have write input type hidden' what name is equal to hidden price with value is equal to open and close PHP tagging between tag I have write echo statement with row variable is equal to call a name price this both hidden fields' value will be submitted when form submitted this hidden fields' value will be submitted lastly I want to add add to cart' button for add item to Shopping Cart so for this I have right input type is equal to submit what name is equal to add to cart with value is equal to add to cart by click on this button buyer can add item to its shopping cart now I have saved this code uncheck output on browser friends you can see three product with product image product name product price text box for quantity buyer can enter quantity value into this text box and lastly is Add to Cart button when buyer click on this button item will be added into the shopping cart now I have moved to item add to shopping cart code here when you click on add to cart button then item will be added to shopping cart so I have write a statement with condition and in condition I have rights at function with parameter like Dollar post add to cart which is name of submit button this block of code will execute only when use click on the add the Cart button this condition will check this event between this block I have create one session variable with name shopping cart and this variable I will store all the item more to data first I want to check the session variable has some data or not so I have write if condition with cid function with parameter like session shopping cart variable this code will check the session shopping cart variable has some data or not if it has data then this block of code will execute otherwise it will execute else block of code suppose shopping card session variable has no data then in else block I have write one item array variable is equal to array into disarray have write item add key which I have get from this gated variable from URL item name get from hidden field like hidden name item price get from hidden field like hidden price field and item quantity get from textbox with name quantity this way we can store all details of item into item array variable now I want to store this details to shopping cart session variable so I have right session shopping cart variable with index 0 is equal to item array this way we can store all item details to the session shopping cart variable now friends suppose sessions shopping-cart variable has data then at that time if block of code will execute so in this block first i want to get the data of item it in array format so for this i have right item in array variable is equal to a column function with two parameter one parameter is array from which you want to get column of data and second is column name this is the name of column you want to get the data now itemid data are stored into this side to mid array variable in array format now I have write if statement with condition like not operator with an array function with two parameter in first parameter I have write dollar get with it value get from URL this specifies the but to search from second parameter like item in array this function searches an array for a specific value that means it's search Heights made from the item in array with not operator it judge a fight amid not present an item in array then we'll add item data otherwise it will display item already added into the shopping cart suppose item not added into the shopping cart then it will execute if block of code and if block of code I have write count variable is equal to count function with parameter like session shopping cart variable this count function will count the number of element in an array and store into count variable after this I have write item array variable is equal to a rain beret have store the item mid get from getted variable from URL item name from hidden name field item price get from hidden price field and item quantity get from text box with named quantity this we can store all item details into item or a variable now I want to store this details into session shopping cart variable so I have right session shopping cart with index number which I have store into count variable is equal to item array this way we can store item detail into session shopping cart variable with proper index number but suppose they're specified I'm already add-in to shopping cart an else block of code will execute so in else block I have right echo statement for display alert message like item already added when buyer click on ok then page should be redirect to index dot PHP link so for this I have write echo statement with text like open and close script tag in between this tag I have right window dot location is equal to index dot PHP this will redirect page to this link now I want to display shopping cart details to buyer it want to display this details like item name quantity price total and action field and table format after this I want to display item which have added into shopping cart so here first I want to check this session shopping cart is not empty so for this I have right of statement with not operator with empty function with parameter like session shopping cart variable this condition will check the session variable is not empty if it is empty it will not display anything on webpage but suppose it is not empty so it will execute this if block code in this block first I have write total variable is equal to zero this variable is used to store the total of item price after this I have right for each loop with open and closed bracket and between bracket I have right shopping card session array as keys with values by using this loop this shopping cart array divided into two parts keys and values this way we can access all element of session shopping card array now I want to print element on web page in table format first I want to print item name so I have write table data tag and between this tag I have write values with keys name item name after this I want to print item quantity so I have right table data tag and between this tag I have write values with keys name item quantity after this I want to print item price so I have right table data tag and between this tag I have write values with keys like item price after this I want to print value of item price into item quantity so I have right table data tag in between this tag I have right number format function and between this function I have right item quantity into item price comma two this function will convert number into two decimal point after this I want to print remove link for remove item from shopping card so for this I have write anchor tag with attribute 'href is equal to index dot PHP question mark action is equal to delete and it is equal to dynamic at mid from session so I have write values with keys like item it now at last I want to get the total price of all out product unto Shopping Cart so here I have write total variable is equal to total plus open and close bracket and between bracket I have right item quantity into item price now I want to print this total price of all item so I have right table data tag and between this tag I have right number format function with parameter like total variable with two decimal point lastly I have show you how to remove item from shopping cart suppose buyer want to remove item from shopping cart then buyer can click on this remove link and he can remove product from shopping cart in this remove link I have passed two variable one is action is equal to delete and second is it of item when I click on remove item link then in URL you can see action is equal to delete so here I have write of statement with condition like sit function with parameter get action variable this condition check get action variable is set and did not null if the get action variable is set then this if block of code will execute and under this block I have a gain right if condition with get action variable is equal to delete this condition check action is equal to delete or not if action is equal to delete then this if block of code will execute and under this block I have right for each loop with sessions Shopping Cart variable as keys with values with help of this for each loop we can access each keys and values of session shopping cart variable now under this we want to remove item from the shopping cart or a indiv item get from the URL so for this I have right of condition with values with keys name item it is equal to get variable lid here it we have get from URL this condition will check irate item it is equal to get it which get from which item you want to delete and get from URL if you're a item 8 is equal to get to end this if block of code will execute and under this block I have right unset function with parameter like session shopping cart variable with index keys this unset function will destroy variable of shopping cart or a and here keys which have get from for each loop now I want to display alert message like item removed so for this I have right echo statement with open and closed script tag and between this tag I have write alert message like item removed after item remove they want to read a rec page to index dot PHP page so I have right echo statement with open and closed script tagging between this tag I have right window dot location is equal to index dot PHP this will redirect page to index dot PHP page friends our simple shopping cart is ready by using PHP so I have saved this code and check the output on web page our shopping cart is ready here we can add product to shopping cart and below you can see the item which I have added to our cart with details like item name quantity price if you already add item to cart again you cannot that item to cart you can also remove item from this shopping cart here all the transaction are not store in database but this all store in session variable so this will increase speed of out online store this is because all the item data are stored in session variable once buyer put order all session value will be cleared you so this is my simple shopping cart by using PHP with MySQL database if you liked this video please share this video with your friends and even you can also share this video on social media also friends you want to get more update of my video so friends you can subscribe my youtube channel friends you can also like my Facebook page also or you can also follow webs listen on Twitter
Info
Channel: Webslesson
Views: 595,625
Rating: undefined out of 5
Keywords: php shopping cart, php mysql shopping cart, create shopping cart, php shopping cart tutorial using sessions, make shopping cart, create shopping cart with php, simple php shopping cart, cart in php, shopping cart in php, shopping cart website, php mysql shopping cart code, php mysql shopping cart tutorial, php mysql shopping cart scripts, php shopping cart tutorial, php shopping cart source code
Id: 0wYSviHeRbs
Channel Id: undefined
Length: 19min 12sec (1152 seconds)
Published: Wed Aug 03 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.