PHP simple shopping basket
Hi i am making a website in dreamweaver using php connected to database tables in a phpmyadmin server.
I need to create a simple shopping basket where the user selects an item from one page using a link that saves the products id of the selected product and then the website will go to a blank insert page that will add the item to the shopping basket database table and when it has done that it will go back to the original page.
I have 3 database tables members, Products and shopping basket the details that will need to be sent to the shopping basket table are product Id, Product name and price which are all found in the products table and it will also need to send the username of the user from the members table to the shopping basket table aswell.
Could anybody help me with the code to insert data from one table to another using a primary key product ID?
Welcome to the forums wardy91. You did not say what database you were using. I'm assuming MySQL, if different the idea is the same, implementation maybe slightly different.
You do not want to put the same information in different tables. It just wastes space. We can retrieve the data we need with JOINs. You have three tables members which contains custumer name and id
products which contains product id, name and cost
basket which should contains order number, order date, order status, custumer id and product id.
Lets just get the customer name, the product he/she ordered, and the oder number and status.
select o.ord_num, o.ord_status, c.cust_name, p.prod_desc from orders_tbl as o
JOIN customer_tbl as c
on o.cust_id = c.cust_id
join products_tbl as p
on p.prod_id = o.prod_id
where o.ord_num = '16C17'
or if we have the customers name we substitute where c.cust_name = 'PUT NAME HERE'
I am assuming that you know how to insert data. Your ordering form should give you the customer's name and what he ordered so you need to know how to generate the order number, order date, and order status. If you do you got it made, if not ask here.
Thank you for the help I will give it a go. Yeah its using a mysql database
|All times are GMT +1. The time now is 09:00 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.