SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting multiple row in database in php

    Dear All

    please see my below script.

    I have 3 table, tbl_orde, tbl_ord2 & tbl_fab.

    I am inserting data from one form. But have to insert two row in tbl_fab. But my sql3 & sql4 query is not working at a times, i mean not inserting 2 row, only adding one row. plz help on it...

    PHP Code:
    <?php 
          $fact 
    = (isset($_POST['fact'])) ? $_POST['fact'] : '';
          
    $fdept = (isset($_POST['fdept'])) ? $_POST['fdept'] : '';
          
    $fdesig = (isset($_POST['fdesig'])) ? $_POST['fdesig'] : '';
          
    $fusername = (isset($_POST['fusername'])) ? $_POST['fusername'] : '';
          
    $fsecretcode = (isset($_POST['fsecretcode'])) ? $_POST['fsecretcode'] : '';
          
    $funiqkey = (isset($_POST['funiqkey'])) ? $_POST['funiqkey'] : '';
          
    $buyh = (isset($_POST['buyh'])) ? $_POST['buyh'] : '';
          
    $buyr = (isset($_POST['buyr'])) ? $_POST['buyr'] : '';
          
    $depnn = (isset($_POST['depnn'])) ? $_POST['depnn'] : '';
          
    $depf = (isset($_POST['depf'])) ? $_POST['depf'] : '';
          
    $brand = (isset($_POST['brand'])) ? $_POST['brand'] : '';
          
    $buymer = (isset($_POST['buymer'])) ? $_POST['buymer'] : '';
          
    $year = (isset($_POST['year'])) ? $_POST['year'] : '';
          
    $season = (isset($_POST['season'])) ? $_POST['season'] : '';
          
    $artstyl_no = (isset($_POST['artstyl_no'])) ? $_POST['artstyl_no'] : '';
          
    $order_no = (isset($_POST['order_no'])) ? $_POST['order_no'] : '';
          
    $shipmentdate = (isset($_POST['shipmentdate'])) ? $_POST['shipmentdate'] : '';
          
    $items = (isset($_POST['items'])) ? $_POST['items'] : '';
          
    $orderqty = (isset($_POST['orderqty'])) ? $_POST['orderqty'] : '';
          
    $unitin = (isset($_POST['unitin'])) ? $_POST['unitin'] : '';
          
    $pricein = (isset($_POST['pricein'])) ? $_POST['pricein'] : '';
          
    $unitprice = (isset($_POST['unitprice'])) ? $_POST['unitprice'] : '';
          
    $a $orderqty $unitprice;
          
    $b substr("$shipmentdate"0, -3);
          
    $ordrmks = (isset($_POST['ordrmks'])) ? $_POST['ordrmks'] : '';
          
    $contract_no = (isset($_POST['contract_no'])) ? $_POST['contract_no'] : '';
          
          
    $shipmood = (isset($_POST['shipmood'])) ? $_POST['shipmood'] : '';
          
    $size_range = (isset($_POST['size_range'])) ? $_POST['size_range'] : '';
          
    $ttlcombo = (isset($_POST['ttlcombo'])) ? $_POST['ttlcombo'] : '';
          
    $ttlfabcol = (isset($_POST['ttlfabcol'])) ? $_POST['ttlfabcol'] : '';
          
    $print = (isset($_POST['print'])) ? $_POST['print'] : '';
          
    $emb = (isset($_POST['emb'])) ? $_POST['emb'] : '';
          
    $wash = (isset($_POST['wash'])) ? $_POST['wash'] : '';
          
    $destination = (isset($_POST['destination'])) ? $_POST['destination'] : '';
          
          
    $fab_type1 = (isset($_POST['fab_type1'])) ? $_POST['fab_type1'] : '';
          
    $fab_name1 = (isset($_POST['fab_name1'])) ? $_POST['fab_name1'] : '';
          
    $fab_comp1 = (isset($_POST['fab_comp1'])) ? $_POST['fab_comp1'] : '';
          
    $gsm1 = (isset($_POST['gsm1'])) ? $_POST['gsm1'] : '';
          
    $spcialeft1 = (isset($_POST['spcialeft1'])) ? $_POST['spcialeft1'] : '';
          
    $yarncount1 = (isset($_POST['yarncount1'])) ? $_POST['yarncount1'] : '';
          
    $fab_rmks1 = (isset($_POST['fab_rmks1'])) ? $_POST['fab_rmks1'] : '';
          
          
    $fab_type2 = (isset($_POST['fab_type2'])) ? $_POST['fab_type2'] : '';
          
    $fab_name2 = (isset($_POST['fab_name2'])) ? $_POST['fab_name2'] : '';
          
    $fab_comp2 = (isset($_POST['fab_comp2'])) ? $_POST['fab_comp2'] : '';
          
    $gsm2 = (isset($_POST['gsm2'])) ? $_POST['gsm2'] : '';
          
    $spcialeft2 = (isset($_POST['spcialeft2'])) ? $_POST['spcialeft2'] : '';
          
    $yarncount2 = (isset($_POST['yarncount2'])) ? $_POST['yarncount2'] : '';
          
    $fab_rmks2 = (isset($_POST['fab_rmks2'])) ? $_POST['fab_rmks2'] : '';    
          
          
    $errors       ""
          
    $displayform '1'


     
          if (isset(
    $_POST['ac']) && $_POST['ac'] == 'login') {  // start of login if 
             
    if(preg_match("/^[0-9\"\']+$/"$_POST["funiqkey"]) === 0){
              
    $errFuniqkey '<p class="errText">Uniq key must be in digits</p>';
              
    $error 'YES';
            }
            
            
            if (
    $error != 'YES'){ // only insert data if no errors 
               
    $displayform '0'// disable form show 
               
    $fact mysql_real_escape_string($_POST['fact']); 
               
    $fdept mysql_real_escape_string($_POST['fdept']); 
               
    $fdesig mysql_real_escape_string($_POST['fdesig']); 
               
    $fusername mysql_real_escape_string($_POST['fusername']); 
               
    $fsecretcode mysql_real_escape_string($_POST['fsecretcode']); 
               
    $funiqkey mysql_real_escape_string($_POST['funiqkey']); 
               
    $buyh mysql_real_escape_string($_POST['buyh']);
               
    $buyr mysql_real_escape_string($_POST['buyr']);
               
    $depnn mysql_real_escape_string($_POST['depnn']);
               
    $depf mysql_real_escape_string($_POST['depf']);
               
    $brand mysql_real_escape_string($_POST['brand']);
               
    $buymer mysql_real_escape_string($_POST['buymer']);
               
    $year mysql_real_escape_string($_POST['year']);
               
    $season mysql_real_escape_string($_POST['season']);
               
    $artstyl_no mysql_real_escape_string($_POST['artstyl_no']);
               
    $order_no mysql_real_escape_string($_POST['order_no']);
               
    $shipmentdate mysql_real_escape_string($_POST['shipmentdate']);
               
    $items mysql_real_escape_string($_POST['items']);
               
    $orderqty mysql_real_escape_string($_POST['orderqty']);
               
    $unitin mysql_real_escape_string($_POST['unitin']);
               
    $pricein mysql_real_escape_string($_POST['pricein']);
               
    $unitprice mysql_real_escape_string($_POST['unitprice']);
               
    $ordrmks mysql_real_escape_string($_POST['ordrmks']);
      
               
    $contract_no mysql_real_escape_string($_POST['contract_no']);
          
          
    $shipmood mysql_real_escape_string($_POST['shipmood']);
          
    $size_range mysql_real_escape_string($_POST['size_range']);
          
    $ttlcombo mysql_real_escape_string($_POST['ttlcombo']);
          
    $ttlfabcol mysql_real_escape_string($_POST['ttlfabcol']);
          
    $print mysql_real_escape_string($_POST['print']);
          
    $emb mysql_real_escape_string($_POST['emb']);
          
    $wash mysql_real_escape_string($_POST['wash']);
          
    $destination mysql_real_escape_string($_POST['destination']);
          
          
    $fab_type1 mysql_real_escape_string($_POST['fab_type1']);
          
    $fab_name1 mysql_real_escape_string($_POST['fab_name1']);
          
    $fab_comp1 mysql_real_escape_string($_POST['fab_comp1']);
          
    $gsm1 mysql_real_escape_string($_POST['gsm1']);
          
    $spcialeft1 mysql_real_escape_string($_POST['spcialeft1']);
          
    $yarncount1 mysql_real_escape_string($_POST['yarncount1']);
          
    $fab_rmks1 mysql_real_escape_string($_POST['fab_rmks1']);
          
          
    $fab_type2 mysql_real_escape_string($_POST['fab_type2']);
          
    $fab_name2 mysql_real_escape_string($_POST['fab_name2']);
          
    $fab_comp2 mysql_real_escape_string($_POST['fab_comp2']);
          
    $gsm2 mysql_real_escape_string($_POST['gsm2']);
          
    $spcialeft2 mysql_real_escape_string($_POST['spcialeft2']);
          
    $yarncount2 mysql_real_escape_string($_POST['yarncount2']);
          
    $fab_rmks2 mysql_real_escape_string($_POST['fab_rmks2']);
          
      
      
      
      
               
                     if(!
    $fsecretcode ){
                    
    //if any weren't display the error message
                    
    echo "<center>You need to fill in all of the required (* marked) fields!</center>";
                }
           else{

               
    $sql mysql_query("INSERT INTO tbl_order 
                                           SET   fact = '
    $fact', 
                                                 fdept = '
    $fdept', 
                                                 fdesig = '
    $fdesign', 
                                                 fusername = '
    $fusername', 
                                                 fsecretcode = '
    $fsecretcode', 
                                                 funiqkey = '
    $funiqkey',
                                                 buyh = '
    $buyh',
                                                 buyr = '
    $buyr', 
                                                 depnn = '
    $depnn',
                                                 depf = '
    $depf',
                                                 brand = '
    $brand',
                                                 buymer = '
    $buymer',
                                                 year = '
    $year',
                                                 season = '
    $season',
                                                 artstyl_no = '
    $artstyl_no',
                                                 order_no = '
    $order_no',
                                                 shipmentdate = '
    $shipmentdate',
                                                 items = '
    $items',
                                                 orderqty = '
    $orderqty',
                                                 unitin = '
    $unitin',
                                                 pricein = '
    $pricein',
                                                 unitprice = '
    $unitprice',
                                                 ttlprice = '
    $a',
                                                 ordrmks = '
    $ordrmks',
                                                 shipmonth = '
    $b',
                                                 ship_status= '1',                                             
                                                 contract_no= '
    $contract_no'                                             
                                                 "
    ); 
                                                 

                                                 
           
    $select mysql_query("SELECT tbl_order_id FROM tbl_order ORDER BY tbl_order_id DESC");
           
    $return mysql_fetch_assoc($select);
           
    $idx $return['tbl_order_id'];
           
    $newId $idx 0;
                                                 
    //$authId = mysql_insert_id();
                                                 
              
    if (!$sql) {  
               echo 
    'Mysql error, data not saved, try again -' mysql_error();               
               
    $displayform '1'// show form to try again 
              
    }else{ 
                                
                   
    $sql2 mysql_query("INSERT INTO tbl_ord2 
                                           SET   order2_tbl_order_id = '
    $newId', 
                                                 order2_funiqkey = '
    $funiqkey',
                                                 order2_order_no = '
    $order_no',
                                                 order2_artstyl_no = '
    $artstyl_no',
                                                 shipmood = '
    $shipmood',
                                                 size_range = '
    $size_range',
                                                 ttlcombo = '
    $ttlcombo',
                                                 ttlfabcol = '
    $ttlfabcol',
                                                 print = '
    $print',
                                                 emb = '
    $emb',
                                                 wash = '
    $wash',
                                                 destination = '
    $destination'
                                                 
                                                  "
    );

    if (!empty(
    $fab_type1)) $sql3 mysql_query ("INSERT INTO tbl_fab 
                                          SET    fab_tbl_order_id = '
    $newId', 
                                                 fab_funiqkey = '
    $funiqkey',
                                                 fab_order_no = '
    $order_no',
                                                 fab_artstyl_no = '
    $artstyl_no',
                                                 fab_type = '
    $fab_type1', 
                                                 fab_name = '
    $fab_name1',
                                                 fab_comp = '
    $fab_comp1',
                                                 fab_gsm = '
    $gsm1',
                                                 fab_splefct = '
    $spcialeft1',
                                                 fab_ycount = '
    $yarncount1',
                                                 fab_rmks = '
    $fab_rmks1
                                                 "
    );     
    if (!empty(
    $fab_type2)) $sql4 mysql_query ("INSERT INTO tbl_fab 
                                          SET    fab_tbl_order_id = '
    $newId', 
                                                 fab_funiqkey = '
    $funiqkey',
                                                 fab_order_no = '
    $order_no',
                                                 fab_artstyl_no = '
    $artstyl_no',
                                                 fab_type = '
    $fab_type2', 
                                                 fab_name = '
    $fab_name2',
                                                 fab_comp = '
    $fab_comp2',
                                                 fab_gsm = '
    $gsm2',
                                                 fab_splefct = '
    $spcialeft2',
                                                 fab_ycount = '
    $yarncount2',
                                                 fab_rmks = '
    $fab_rmks2
                                                 "
    );     
                                                                  

                                         
                 die(
    'Your data was inserted <a href="vod.php">Click Here to View Update Details</a> <a href="ano.php">Click Here to Add New Orders</a>');  }

              } 
     
            } 
    // end of insert if 
          
    // end of  login if 
     
      
    if ($displayform '1') { // only show form if required 
        
    require("dano.php");
      
    ?>  
    <?php  
      
    // end of form display if 
    ?>

  2. #2
    Web development Company chrisranjana's Avatar
    Join Date
    Jan 2001
    Location
    chennai , tamil nadu , India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mehidy View Post
    But my sql3 & sql4 query is not working at a times, i mean not inserting 2 row, only adding one row. plz help on it...
    Are the variables $fab_type1 and $fab_type2 set always ?
    Chris, Programmer/Developer, Chrisranjana.com
    Chennai, Tamil Nadu, India.
    Php Developers, Ruby on Rails Developers


Bookmarks

Posting Permissions

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