Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 546 Times in 545 Posts
    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.
    Evolution - The non-random survival of random variants.

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the help I will give it a go. Yeah its using a mysql database


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •