dltemplate Posted May 17, 2014 Share Posted May 17, 2014 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 https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/ Share on other sites More sharing options...
Barand Posted May 17, 2014 Share Posted May 17, 2014 Read up on data normalization Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479829 Share on other sites More sharing options...
dltemplate Posted May 17, 2014 Author Share Posted May 17, 2014 thanks, i will follow it., if i have question please dont stop replying me Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479831 Share on other sites More sharing options...
dltemplate Posted May 17, 2014 Author Share Posted May 17, 2014 boss i dont get info much, im sorry but im newbie with php please if you have a code to combine those data into 1 variable that i can insert into my database order, please share to me. thanks Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479832 Share on other sites More sharing options...
Barand Posted May 17, 2014 Share Posted May 17, 2014 The point is that putting them in one field is the wrong way to do it http://lmgtfy.com/?q=data+normalization Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479834 Share on other sites More sharing options...
Barand Posted May 17, 2014 Share Posted May 17, 2014 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 https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479836 Share on other sites More sharing options...
dltemplate Posted May 17, 2014 Author Share Posted May 17, 2014 very confusing but will try to analyze =) i will see if i can get your point here Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479837 Share on other sites More sharing options...
dltemplate Posted May 17, 2014 Author Share Posted May 17, 2014 sir, what about the table for order? do you have diagram like your post while ago? i want to see what it must look like. Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479845 Share on other sites More sharing options...
Barand Posted May 17, 2014 Share Posted May 17, 2014 Do you mean like this Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479848 Share on other sites More sharing options...
dltemplate Posted May 17, 2014 Author Share Posted May 17, 2014 i wanna try this now, keep you posted sir Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479884 Share on other sites More sharing options...
dltemplate Posted May 18, 2014 Author Share Posted May 18, 2014 sir i think cart table must be follow first before we declare the order table because client will finalize his cart before he complete his orders right? what do you think sir, please advise me. thank you Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479886 Share on other sites More sharing options...
dltemplate Posted May 18, 2014 Author Share Posted May 18, 2014 sir i have attached the structure design of my database, please review and advise me what to correct Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479888 Share on other sites More sharing options...
Barand Posted May 18, 2014 Share Posted May 18, 2014 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 https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479904 Share on other sites More sharing options...
dltemplate Posted May 18, 2014 Author Share Posted May 18, 2014 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 https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479906 Share on other sites More sharing options...
dltemplate Posted May 18, 2014 Author Share Posted May 18, 2014 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 https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1479987 Share on other sites More sharing options...
Barand Posted May 19, 2014 Share Posted May 19, 2014 See FAQ http://forums.phpfreaks.com/topic/273121-readme-php-resources-faqs/?do=findComment&comment=1405508 Link to comment https://forums.phpfreaks.com/topic/288558-need-help-mysql-php-insert-rows-problem/#findComment-1480022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.