Jump to content

Need help - mysql / php insert rows problem


dltemplate

Recommended Posts

i have created my own code of custom shopping cart

 

i have viewcart.php working great, now when i want to insert the orders from viewcart.php with list of like 5 items, how can i insert 5 names of products into my database 1 row

 

example

 

names are

1. jean

2. mond

3. richard

4. gwen

 

list above is the results of my while loop, now i want to insert those names to my database column[order_productname] so that i can identity what products are paid by my clients.

 

i tried fetch_array but if i assign variable to fetch array result, it only shows 1 which is "jean"

 

i wish this is possible

 

dforth

 

Link to comment
Share on other sites

You should end up with something like this

+----------+--------------+                 +--------------+-------------------+
| ClientId | ClientName   |                 | ProductID    | ProductName       |
+----------+--------------+                 +--------------+-------------------+
|    1     | Jean         |                 |     1        | Product one       |
|    2     | Mond         |                 |     2        | Product two       |
|    3     | Richard      |                 |     3        | Product three     |                 
|    4     | Gwen         |                 |     4        | Product four      |
+----------+--------------+                 |     5        | Product five      |
      |                                     +--------------+-------------------+
      |                                          |
      +----------------------------+             |
                                   |             |
                      Cart         |             |
                      +------+------------+--------------+
                      |  id  | clientId   | productId    |
                      +------+------------+--------------+
                      |   1  |     1      |      1       |
                      |   2  |     1      |      2       |   Client 1 has products
                      |   3  |     1      |      3       |   1, 2, 3, 4 and 5
                      |   4  |     1      |      4       |
                      |   5  |     1      |      5       |
                      |   6  |     2      |      2       |   Client 2 has products
                      |   7  |     2      |      4       |   2, 4, and 5
                      |   7  |     2      |      5       |
                      +------+------------+--------------+

Now, by searching on clientid you know what each client bought. By searching on productid you know who bought each product.

Link to comment
Share on other sites

One field needs clarification before comment, viz.

  • user_date ?

Some should not be in there

  • cart_productname - you should only store the productname in the product table and not repeat in all the cart records
  • cart_productprice - ditto
  • cart_by - cart items belong to the order and you already have order_by
  • cart_subtotal - don't store derived items like totals. Use a query to SUM the items when you want the total.
  • order_total - as above
  • order_productid - an order can be for several products, that's why there is the cart table to hold the productid's
Link to comment
Share on other sites

sir thanks for your data normalization... with that idea i can manage to fix the problem

 

now i am working on payment gateway, if im success, please allow me to share my custom simple cart with you so that you can review or check the bug.

Link to comment
Share on other sites

sir everything works fine in my localhost, but when after uploading all files to webhost, it gives me error please help me how to fix it

 

error is

Warning: Cannot modify header information - headers already sent by (output started at /home/vccandba/public_html/

and my script is

    <?php
        @session_start();
        if (!$_SESSION['signed_in'])
            {


            header("location:index.php");


            }
    ?>

any idea please im stuck with this problem.

 

anyone can access my member page without user authentication, this problem only happen to my webhost, with my local server everything works fine.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.