PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 26th, 2008, 02:41 AM
tester1000 tester1000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 tester1000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 50 sec
Reputation Power: 0
Send multi data than insert in db?

Hi all!

I have a shop script and i try to make a big FORM for ordering direct from this.

frist i read out the group+category+product(id, name) than i have the for ... so this was simple. but now if i send to the card i get only one product in the cart becaus all from have the same hidden name. :


PHP Code:
 session_start();
    if (!empty(
$_POST['numprod'])) {
          
$numprod=$_POST['numprod'];
      }
      if (!empty(
$_POST['pname'])) {
          
$prodid=$_POST['$pname'];
      }
      if (!empty(
$_POST['basketid'])) {
          
$basketid=$_POST['basketid'];
      }
if (!empty(
$_GET['op'])) {
             
$op=$_GET['op'];
      }
  
   if(!isset(
$_SESSION['cart3']))
   {
              
$_SESSION['cart3'] = array();       
   }




<
form method="POST" action="index.php?page=cart&action=add">

                    
                    <?
            
            
$sql_k "SELECT ID, NAME FROM shopgroup ORDER BY ID ASC";
             
$result_k mysql_query($sql_k) or die(mysql_error());

             while (
$record_k mysql_fetch_array($result_k)) // list group
             
{            
                 echo 
"<div class=\"na\"> $record_k[NAME] </div>";
                 
                 
$sql_pk "SELECT * FROM shopcategory WHERE GROUPID = '$record_k[ID]'";
                 
$result_pk mysql_query($sql_pk) or die(mysql_error());

                 while (
$record_pk mysql_fetch_array($result_pk)) // list category
                 
{
                                                             
                     
                    
$sql_p "SELECT ID, PRODUCTID, PRICE 
                              FROM shopproduct 
                              WHERE CATID = $record_pk[ID] 
                              ORDER BY PRODUCTID ASC"
;
                
                    
$result_p mysql_query($sql_p) or die(mysql_error());    
                    
$i 1;
                        
                    
                    echo 
"<table align=\"center\" border=\"0\" width=\"470\" class=\"list\" cellpadding=\"7\">\n";
                    echo 
"<caption >$record_pk[DESC]</caption>";
                    
//echo $customerid;
                    
echo "<tr><td>\n";
                    
                     while (
$record_p mysql_fetch_array($result_p)) // list product
                    
{
                    
                        
//$pname=  $record_p[PRODUCTID];                 
                        
if($i%4==0
                        {
                            
//echo "<div class=\"pro\">$record_p[PRODUCTID] <input type=\"text\" name=\"numprod\" size=\"5\" class=\"dug\" value=\"1\"  /></div>\n";
                            
echo "<div class=\"pro\">$record_p[PRODUCTID] <input type=\"text\" name=\"numprod\" size=\"5\" class=\"dug\" value=\"1\" /><input type=\"submit\" value=\"ORDER\" name=\"sub\"></div>\n";
                            echo 
"<div class=\"del\">&nbsp;</div>\n";
                        
?><input type="hidden" name="prodid" value="<?php echo $record_p[ID?>"> <?
                                      
                        
}
                        else 
                        echo 
"<div class=\"pro\">$record_p[PRODUCTID] <input type=\"text\" name=\"numprod\" size=\"5\" class=\"dug\" value=\"1\" /><input type=\"submit\" value=\"ORDER\" name=\"sub\"></div>\n";
                        
?><input type="hidden" name="prodid" value="<?php echo $record_p[ID?>"> <?
                        $i
++;
                    }
                    
                    echo 
"</td></tr>\n";
                    echo 
"</table><br /><br />\n";
                 }
                    
                 
             }
             
                               
           
/*    
                   echo "<hr class=\"red\" />
                  <div style=\"text-align:right\">                  
                  
                  </form></div><br />\n";      
    */
                  
echo "<hr class=\"red\" />
                  <div style=\"text-align:right\">                  
                  <input type=\"submit\" name=\"sub\" value=\"order all\" class=\"big\" \" />
                  </form></div><br />\n"
;      
     
 
 }
  
?> 


than send it to :

PHP Code:
function order_now()
        {
              if(
$cart3[$record_p[ID]]!="" AND is_numeric($cart3[$record_p[ID]])) 
                            { 
                                
$qty $cart3[$record_p[ID]];
                                
$productid $qty*$record_p[PRICE];
                            }
                            else 
                            {
                                
$qty "";
                                
$productid "";
                            }
 
            
            
// now lets check if the product we add is new, or we need to update an existing record
           // $query = "SELECT `ID` FROM `".$dbtablesprefix."basket` WHERE `CUSTOMERID` = '".$customerid."' AND `PRODUCTID` = '".$prodid."' AND `FEATURES` = '". $productfeatures . "'";
           // $sql = mysql_query($query) or die(mysql_error());
           //if (mysql_num_rows($sql) == 0) {
        //mysql_query ("INSERT INTO `shopbasket` ( `CUSTOMERID` , `PRODUCTID` , `STATUS` , `ORDERID` , `LINEADDDATE` , `QTY` , `FEATURES`) VALUES ( '" . $customerid . "', '" . $prodid . "', 'BASKET', '0' , '" . Date("d-m-Y @ G:i") . "' , '" . $numprod . "', '".$productfeatures. "')") or die(mysql_error());
                        
            //echo $qty;
            //echo $productid;
            
            //echo "insert ok";
            //}
  //$sql = mysql_query($query) or die(mysql_error());
   
header ('location:http://shop/index.php?page=list&action=list&op=ok');
   } 


normaly is for one product so i have to put it in a array? could someone help me please?

Reply With Quote
  #2  
Old April 11th, 2008, 11:51 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 530 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 4 m 40 sec
Reputation Power: 3
arrays in database

Hi tester1000, welcome to the forums
I would probably give each input it's own name. But not always. You can pass arrays from a form and insert them into a single database field by using serialize() so the value becomes a string something like
"a:3,s:3(hat),s:4(coat),s:3(tie)"
When you get the values from the database use unserialize() to get the array.
__________________
WP plugins - Error Reporting, Clean Options
http://www.mittineague.com/dev/er.php
http://www.mittineague.com/dev/co.php

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Send multi data than insert in db?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway