SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem in saving data from while loop and select option

    Hi..

    I need to save data from a while loop and data from select option, Now I encountered that using my query I only save is the last part of my while loop and also the data that I choose in select option did not save.

    here is my code:

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    $sr_date = $_POST['sr_date'];
    $sr_number = $_POST['sr_number'];
    $Items = $_POST['Items'];
    $SubItems = $_POST['SubItems'];
    $ItemCode = $_POST['ItemCode'];
    $DemandedQty = $_POST['DemandedQty'];
    $UoM = $_POST['UoM'];
    $Class = $_POST['Class'];
    $Description = $_POST['Description'];
    $BINLocation = $_POST['BINLocation'];
    $RequestedBy = $_POST['RequestedBy'];
    $ApprovedBy = $_POST['ApprovedBy'];
    $ReceivedBy = $_POST['ReceivedBy'];
    $IssuedBy = $_POST['IssuedBy'];
    
    $sql = "INSERT INTO stock_requisition
    (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy,
    ApprovedBy, ReceivedBy, IssuedBy)
    VALUES
    ('$sr_date', '$sr_number', '$Items', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description',
    '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy')
    ON DUPLICATE KEY UPDATE
    sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty',
    UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy',
    ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'";
    
    $result = mysql_query($sql, $con);
    
            $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
            } 
            else {
    
    
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
    
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
    
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }
            
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);  
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    
    <script type="text/javascript">
    function save_sr(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var Items = document.getElementById("Items").value;
        var SubItems = document.getElementById("SubItems").value;
        var ItemCode = document.getElementById("ItemCode").value;
        var DemandedQty = document.getElementById("DemandedQty").value;
        var UoM = document.getElementById("UoM").value;
        var Class = document.getElementById("Class").value;
        var Description = document.getElementById("Description").value;
        var BINLocation = document.getElementById("BINLocation").value;
        var RequestedBy = document.getElementById("RequestedBy").value;
        var ApprovedBy = document.getElementById("ApprovedBy").value;
        var ReceivedBy = document.getElementById("ReceivedBy").value;
        var IssuedBy = document.getElementById("IssuedBy").value;
        
        document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+
        "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+
        Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+
        "&IssuedBy="+IssuedBy;
        document.stock_requisition.submit();
        
        alert("Stock Requisition data save.");
        window.location = "StockRequisition.php";
        
        
    }
    </script>
    </head>
    <body>
    <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li>
    </ul>
    </div>
    
    <div id="ddcolortabs1">
    <ul>
    <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    </ul>
    </div>
    
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>SR# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;">
    <br/> 
    </div> 
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
            </tr>";       
    
    $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error());
    
    $res_sub = mysql_query($sql, $con);  
     while($row_sub = mysql_fetch_assoc($res_sub)){
    
        echo "<tr>
            <td style='border: none;'>&nbsp;</td>
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems' value='$row_sub[SubItems]' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode' value='$row_sub[ItemCode]' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM' value='$row_sub[UoM]' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class' value='$row_sub[Class]' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description' value='$row_sub[Description]' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation' value='$row_sub[BINLocation]' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>     
            </tr>";
    }
    }   
                   
    ?>
    </table>
    </div>
    
    <div id='RequestedBy'>
    <label>Requested By:</label>
    <select name="Requested_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ApprovedBy'>
    <label>Approved By:</label>
    <select name="Approved_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ReceivedBy'>
    <label>Received By:</label>
    <select name="Received_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id='IssuedBy'>
    <label>Issued By:</label>
    <select name="Issued BY">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onclick="save_sr()">
    </div>
    </body>
    </html>
    I also I attach the display data.

    Thank you
    Attached Images Attached Images

  2. #2
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi..

    I revised my code and I already resolved my problem in select option.

    Now my problem is how can I save in my database the data that display in a form as same as what it display.
    Honestly, it's my first time to encounter this kind of saving and i have no idea how possible it is.

    here is my new code:
    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore");
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
           
           
            $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
                
            } 
            else {
    
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
    
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }        
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);   
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    
    
    <script type="text/javascript">
    function save_sr(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var Items = document.getElementById("Items").value;
        var SubItems = document.getElementById("SubItems").value;
        var ItemCode = document.getElementById("ItemCode").value;
        var DemandedQty = document.getElementById("DemandedQty").value;
        var UoM = document.getElementById("UoM").value;
        var Class = document.getElementById("Class").value;
        var Description = document.getElementById("Description").value;
        var BINLocation = document.getElementById("BINLocation").value;
        var RequestedBy = document.getElementById("RequestedBy").value;
        var ApprovedBy = document.getElementById("ApprovedBy").value;
        var ReceivedBy = document.getElementById("ReceivedBy").value;
        var IssuedBy = document.getElementById("IssuedBy").value;
        
        document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+
        "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+
        Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+
        "&IssuedBy="+IssuedBy;
        document.stock_requisition.submit();
        
        alert("Stock Requisition data save.");
        window.location = "StockRequisition.php";
        
        
    }
    </script>
    </head>
    <body>
    <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li>
    </ul>
    </div>
    
    <div id="ddcolortabs1">
    <ul>
    <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    </ul>
    </div>
    
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>SR# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;">
    <br/> 
    </div> 
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$Items' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
            </tr>";       
    
    $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error());
    $res_sub = mysql_query($sql, $con);  
     while($row_sub = mysql_fetch_assoc($res_sub)){
         
         $SubItems = $row_sub['SubItems'];
         $ItemCode = $row_sub['ItemCode'];
         $UoM = $row_sub['UoM'];
         $Class = $row_sub['Class'];
         $Description = $row_sub['Description'];
         $BINLocation = $row_sub['BINLocation'];
         
         
    
        echo "<tr>
            <td style='border: none;'>&nbsp;</td>
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto; size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;></td>     
            </tr>";
    }
    }   
                   
    ?>
    </table>
    </div>
    <?php
       $RequestedBy = array('AAA', 'BBB', 'CCC', 'DDD');
       
       $ApprovedBy = array('EEE', 'FFF', 'GGG', 'HHH');
       
       $ReceivedBy = array('III', 'JJJ', 'KKK', 'LLL');
       
       $IssuedBy = array('MMM', 'NNN', 'OOO', 'PPP'); 
    
    ?>
    
     <div id='Requested_By'>
    <label>Requested By:</label>
     <select name="RequestedBy">
     <option value="Select">Select</option>
     <option value="AAA" <?php if($_POST['RequestedBy'] == 'AAA') echo "selected='selected'"; ?>>AAA</option>
      <option value="BBB" <?php if($_POST['RequestedBy'] == 'BBB') echo "selected='selected'"; ?>>BBB</option>
     <option value="CCC" <?php if($_POST['RequestedBy'] == 'CCC') echo "selected='selected'"; ?>>CCC</option>
      <option value="DDD" <?php if($_POST['RequestedBy'] == 'DDD') echo "selected='selected'"; ?>>DDD</option>
     </select>
    </div>
    
    <div id='Approved_By'>
    <label>Approved By:</label>
    <select name="ApprovedBy">
    <option name='Select'>Select</option>
    <option value="EEE" <?php if($_POST['ApprovedBy'] == 'EEE') echo "selected='selected'"; ?>>EEE</option>
      <option value="FFF" <?php if($_POST['ApprovedBy'] == 'FFF') echo "selected='selected'"; ?>>FFF</option>
     <option value="GGG" <?php if($_POST['ApprovedBy'] == 'GGG') echo "selected='selected'"; ?>>GGG</option>
      <option value="HHH" <?php if($_POST['ApprovedBy'] == 'HHH') echo "selected='selected'"; ?>>HHH</option>
    </select>
    </div>
    
    <div id='Received_By'>
    <label>Received By:</label>
    <select name="ReceivedBy">
    <option name='Select'>Select</option>
    <option value="III" <?php if($_POST['ReceivedBy'] == 'III') echo "selected='selected'"; ?>>III</option>
      <option value="JJJ" <?php if($_POST['ReceivedBy'] == 'JJJ') echo "selected='selected'"; ?>>JJJ</option>
     <option value="KKK" <?php if($_POST['ReceivedBy'] == 'KKK') echo "selected='selected'"; ?>>KKK</option>
      <option value="LLL" <?php if($_POST['ReceivedBy'] == 'LLL') echo "selected='selected'"; ?>>LLL</option>
    </select>
    </div>
    
    <div id='Issued_By'>
    <label>Issued By:</label>
    <select name="IssuedBy">
    <option name='Select'>Select</option>
    <option value="MMM" <?php if($_POST['IssuedBy'] == 'MMM') echo "selected='selected'"; ?>>MMM</option>
      <option value="NNN" <?php if($_POST['IssuedBy'] == 'NNN') echo "selected='selected'"; ?>>NNN</option>
     <option value="OOO" <?php if($_POST['IssuedBy'] == 'OOO') echo "selected='selected'"; ?>>OOO</option>
      <option value="PPP" <?php if($_POST['IssuedBy'] == 'PPP') echo "selected='selected'"; ?>>PPP</option>
    </select>
    </div>
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onclick="save_sr()">
    </div>
    </body>
    </html>
    Any help is higly appreciated.

    Thank you

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi..

    I really tried my best to resolve my problem in saving data from while loop.

    I revised again my code:

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore");
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    $sr_date = $_POST['sr_date'];
    $sr_number = $_POST['sr_number'];
    $Items = $_POST['Items'];
    $SubItems = $_POST['SubItems'];
    $ItemCode = $_POST['ItemCode'];
    $DemandedQty = $_POST['DemandedQty'];
    $UoM = $_POST['UoM'];
    $Class = $_POST['Class'];
    $Description = $_POST['Description'];
    $BINLocation = $_POST['BINLocation'];
    $RequestedBy = $_POST['RequestedBy'];
    $ApprovedBy = $_POST['ApprovedBy'];
    $ReceivedBy = $_POST['ReceivedBy'];
    $IssuedBy = $_POST['IssuedBy'];
    
    
            $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
            } 
            else {
    
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
    
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
                
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }
           
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);  
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    
    
    <script type="text/javascript">
    function save_sr(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var Items = document.getElementById("Items").value;
        var SubItems = document.getElementById("SubItems").value;
        var ItemCode = document.getElementById("ItemCode").value;
        var DemandedQty = document.getElementById("DemandedQty").value;
        var UoM = document.getElementById("UoM").value;
        var Class = document.getElementById("Class").value;
        var Description = document.getElementById("Description").value;
        var BINLocation = document.getElementById("BINLocation").value;
        var RequestedBy = document.getElementById("RequestedBy").value;
        var ApprovedBy = document.getElementById("ApprovedBy").value;
        var ReceivedBy = document.getElementById("ReceivedBy").value;
        var IssuedBy = document.getElementById("IssuedBy").value;
        
        document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+
        "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+
        Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+
        "&IssuedBy="+IssuedBy;
        document.stock_requisition.submit();
        
        alert("Stock Requisition data save.");
        window.location = "StockRequisition.php";
        
        
    }
    </script>
    </head>
    <body>
    <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li>
    </ul>
    </div>
    
    <div id="ddcolortabs1">
    <ul>
    <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    </ul>
    </div>
    
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>SR# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;">
    <br/> 
    </div> 
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
            </tr>";       
    
    $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error());
    
    $res_sub = mysql_query($sql, $con);  
     while($row_sub = mysql_fetch_assoc($res_sub)){
    
        echo "<tr>
            <td style='border: none;'>&nbsp;</td>
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems' value='$row_sub[SubItems]' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode' value='$row_sub[ItemCode]' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM' value='$row_sub[UoM]' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class' value='$row_sub[Class]' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description' value='$row_sub[Description]' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation' value='$row_sub[BINLocation]' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>     
            </tr>";
            
            
    }
    $sql = "INSERT INTO stock_requisition
    (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy,
    ApprovedBy, ReceivedBy, IssuedBy)
    VALUES
    ('$sr_date', '$sr_number', '$Items', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description',
    '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy')
    ON DUPLICATE KEY UPDATE
    sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty',
    UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy',
    ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'";  
    
    $result = mysql_query($sql, $con);
    
    }   
                   
    ?>
    </table>
    </div>
    
    <div id='RequestedBy'>
    <label>Requested By:</label>
    <select name="Requested_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ApprovedBy'>
    <label>Approved By:</label>
    <select name="Approved_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ReceivedBy'>
    <label>Received By:</label>
    <select name="Received_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id='IssuedBy'>
    <label>Issued By:</label>
    <select name="Issued BY">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onclick="save_sr()">
    </div>
    </body>
    </html>
    and I attach the output where some data is wrong.

    Thank you so much...
    Attached Images Attached Images

  4. #4
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I revised again my code. and now only the first row per items was save.

    here is my code:

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    $sr_date = $_GET['sr_date'];
    $sr_number = $_GET['sr_number'];
    $Items = $_GET['Items'];
    $SubItems = $_GET['SubItems'];
    $ItemCode = $_GET['ItemCode'];
    $DemandedQty = $_GET['DemandedQty'];
    $UoM = $_GET['UoM'];
    $Class = $_GET['Class'];
    $Description = $_GET['Description'];
    $BINLocation = $_GET['BINLocation'];
    $RequestedBy = $_GET['RequestedBy'];
    $ApprovedBy = $_GET['ApprovedBy'];
    $ReceivedBy = $_GET['ReceivedBy'];
    $IssuedBy = $_GET['IssuedBy'];
    
            $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
            } 
            else {
                // Stock Number iteration.... 
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
         
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }
             
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);  
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    
    
    <script type="text/javascript">
    function save_sr(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var Items1 = document.getElementById("Items1").value;
        var SubItems = document.getElementById("SubItems").value;
        var ItemCode = document.getElementById("ItemCode").value;
        var DemandedQty = document.getElementById("DemandedQty").value;
        var UoM = document.getElementById("UoM").value;
        var Class = document.getElementById("Class").value;
        var Description = document.getElementById("Description").value;
        var BINLocation = document.getElementById("BINLocation").value;
        var RequestedBy = document.getElementById("RequestedBy").value;
        var ApprovedBy = document.getElementById("ApprovedBy").value;
        var ReceivedBy = document.getElementById("ReceivedBy").value;
        var IssuedBy = document.getElementById("IssuedBy").value;
        
        document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+
        "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+
        Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+
        "&IssuedBy="+IssuedBy;
        document.stock_requisition.submit();
        
        alert("Stock Requisition data save.");
        window.location = "StockRequisition.php";
        
        
    }
    </script>
    </head>
    <body>
    <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li>
    </ul>
    </div>
    
    <div id="ddcolortabs1">
    <ul>
    <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    </ul>
    </div>
    
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>SR# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;">
    <br/> 
    </div> 
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto; size='5'></td>
            </tr>";       
    
    $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error());
    
    
    $res_sub = mysql_query($sql, $con); 
     while($row_sub = mysql_fetch_array($res_sub)){ 
         $Items1 = $row_sub['Items'];
         $SubItems = $row_sub['SubItems'];
         $ItemCode = $row_sub['ItemCode'];
         $UoM = $row_sub['UoM'];
         $Class = $row_sub['Class'];
         $Description = $row_sub['Description'];
         $BINLocation = $row_sub['BINLocation'];
         
           echo "<tr>
            <td style='border: none;'>&nbsp;<input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto; size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto; size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty[]' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto; size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto; size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;size='10'></td>     
            </tr>";
            
            
    }
     $sql = "INSERT INTO stock_requisition
    (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy,
    ApprovedBy, ReceivedBy, IssuedBy)
    VALUES
    ('$sr_date', '$sr_number', '$Items1', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description',
    '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy')
    ON DUPLICATE KEY UPDATE
    sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items1', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty',
    UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy',
    ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'";  
    
    $result = mysql_query($sql, $con);
    }   
                   
    ?>
    </table>
    </div>
    
    <div id='RequestedBy'>
    <label>Requested By:</label>
    <select name="Requested_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ApprovedBy'>
    <label>Approved By:</label>
    <select name="Approved_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ReceivedBy'>
    <label>Received By:</label>
    <select name="Received_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id='IssuedBy'>
    <label>Issued By:</label>
    <select name="Issued BY">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onclick="save_sr()">
    </div>
    </body>
    </html>
    Sorry...

    I really don't know what the solution..how does an array solve my problem.

    Thank you

  5. #5
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem: only first row was save in database from while loop

    Hi..

    I just want to know how can I save to another table all data that I display using while loop.

    Now I encountered only one row was save.

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); 
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    $sr_date = $_GET['sr_date'];
    $sr_number = $_GET['sr_number'];
    $Items = $_GET['Items'];
    $SubItems = $_GET['SubItems'];
    $ItemCode = $_GET['ItemCode'];
    $DemandedQty = $_GET['DemandedQty'];
    $UoM = $_GET['UoM'];
    $Class = $_GET['Class'];
    $Description = $_GET['Description'];
    $BINLocation = $_GET['BINLocation'];
    $RequestedBy = $_GET['RequestedBy'];
    $ApprovedBy = $_GET['ApprovedBy'];
    $ReceivedBy = $_GET['ReceivedBy'];
    $IssuedBy = $_GET['IssuedBy'];
    
            $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
            } 
            else {
    
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
           
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
    
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }
            
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);  
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    
    
    <script type="text/javascript">
    function save_sr(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var Items1 = document.getElementById("Items1").value;
        var SubItems = document.getElementById("SubItems").value;
        var ItemCode = document.getElementById("ItemCode").value;
        var DemandedQty = document.getElementById("DemandedQty").value;
        var UoM = document.getElementById("UoM").value;
        var Class = document.getElementById("Class").value;
        var Description = document.getElementById("Description").value;
        var BINLocation = document.getElementById("BINLocation").value;
        var RequestedBy = document.getElementById("RequestedBy").value;
        var ApprovedBy = document.getElementById("ApprovedBy").value;
        var ReceivedBy = document.getElementById("ReceivedBy").value;
        var IssuedBy = document.getElementById("IssuedBy").value;
        
        document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+
        "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+
        Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+
        "&IssuedBy="+IssuedBy;
        document.stock_requisition.submit();
        
        alert("Stock Requisition data save.");
        window.location = "StockRequisition.php";
        
        
    }
    </script>
    </head>
    <body>
    <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li>
    </ul>
    </div>
    
    <div id="ddcolortabs1">
    <ul>
    <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    </ul>
    </div>
    
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>SR# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;">
    <br/> 
    </div> 
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;' size='5'></td>
            </tr>";       
    
    
    $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error());
    
    $res_sub = mysql_query($sql, $con); 
     while($row_sub = mysql_fetch_array($res_sub)){ 
    
         $Items1 = $row_sub['Items'];  
         $SubItems = $row_sub['SubItems'];
         $ItemCode = $row_sub['ItemCode'];
         $UoM = $row_sub['UoM'];
         $Class = $row_sub['Class'];
         $Description = $row_sub['Description'];
         $BINLocation = $row_sub['BINLocation'];
    
    
           echo "<tr>
            <td style='border: none;'>&nbsp;<input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td> 
            <!--<td style='border: none;'>&nbsp;<input type='hidden' value='$cast[$i]['id']' id='Items1' name='Items1[]'></td> -->   
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;' size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;' size='10'></td>     
            </tr>";
             
            
    }
     $sql = "INSERT INTO stock_requisition
    (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy,
    ApprovedBy, ReceivedBy, IssuedBy)
    VALUES
    ('$sr_date', '$sr_number', '$Items1', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description',
    '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy')
    ON DUPLICATE KEY UPDATE
    sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items1', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty',
    UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy',
    ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'";  
    
    $result = mysql_query($sql, $con);
    
    }   
                   
    ?>
    </table>
    </div>
    
    <div id='RequestedBy'>
    <label>Requested By:</label>
    <select name="Requested_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ApprovedBy'>
    <label>Approved By:</label>
    <select name="Approved_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ReceivedBy'>
    <label>Received By:</label>
    <select name="Received_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id='IssuedBy'>
    <label>Issued By:</label>
    <select name="Issued BY">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onclick="save_sr()">
    </div>
    </body>
    </html>
    I attach the sample form and output.

    Sorry if I repost my previous thread.

    I hope somebody can help me.

    Thank you
    Attached Images Attached Images

  6. #6
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Try debugging your code. gradually move this line to find where the $value is not returning the expected results:

    PHP Code:
     
     
    echo __LINE__ .' : $value= ' .$value;  die; 
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  7. #7
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when I tried this it did not echo the line.

    I just want to happen is all data in while loop will save all in the database.

    Thank you

  8. #8
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    when I tried this it did not echo the line.

    I just want to happen is all data in while loop will save all in the database.

    Thank you
    Copy and paste these lines into the beginning of your PHP script:

    PHP Code:

    <?php
     $value 
    'fred';
     echo 
    __LINE__ .' : $value= ' .$value;  die;
    Output:
    3 : fred

    Once that is working then:
    1. remove the lines
    2. find the $data that you are trying to save
    3. echo the __LINE__ and the $data
    4. echo your $sql statement
    5. echo the mysql result
    6. continue stepping through the scr[pt
    7. ...
    8. ...
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  9. #9
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this:
    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    $sr_date = $_GET['sr_date'];
    $sr_number = $_GET['sr_number'];
    $Items = $_GET['Items'];
    $SubItems = $_GET['SubItems'];
    $ItemCode = $_GET['ItemCode'];
    $DemandedQty = $_GET['DemandedQty'];
    $UoM = $_GET['UoM'];
    $Class = $_GET['Class'];
    $Description = $_GET['Description'];
    $BINLocation = $_GET['BINLocation'];
    $RequestedBy = $_GET['RequestedBy'];
    $ApprovedBy = $_GET['ApprovedBy'];
    $ReceivedBy = $_GET['ReceivedBy'];
    $IssuedBy = $_GET['IssuedBy'];
    
    
            $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
            } 
            else {
    
                // Stock Number iteration.... 
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
                
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }      
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);  
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    
    <script type="text/javascript">
    function save_sr(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var Items1 = document.getElementById("Items1").value;
        var SubItems = document.getElementById("SubItems").value;
        var ItemCode = document.getElementById("ItemCode").value;
        var DemandedQty = document.getElementById("DemandedQty").value;
        var UoM = document.getElementById("UoM").value;
        var Class = document.getElementById("Class").value;
        var Description = document.getElementById("Description").value;
        var BINLocation = document.getElementById("BINLocation").value;
        var RequestedBy = document.getElementById("RequestedBy").value;
        var ApprovedBy = document.getElementById("ApprovedBy").value;
        var ReceivedBy = document.getElementById("ReceivedBy").value;
        var IssuedBy = document.getElementById("IssuedBy").value;
        
        document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+
        "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+
        Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+
        "&IssuedBy="+IssuedBy;
        document.stock_requisition.submit();
        
        alert("Stock Requisition data save.");
        window.location = "StockRequisition.php";
        
        
    }
    </script>
    </head>
    <body>
    <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li>
    </ul>
    </div>
    
    <div id="ddcolortabs1">
    <ul>
    <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li>
    <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    </ul>
    </div>
    
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>SR# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;">
    <br/> 
    </div> 
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    //$sql = "SELECT Items FROM bom_items ORDER BY Items";
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
            </tr>";       
     $dataArray = array('sr_number' => $sr_number, 'Items' => $Items); 
    $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error());
    
    
    $res_sub = mysql_query($sql, $con); 
     while($row_sub = mysql_fetch_array($res_sub)){ 
       
         $Items1 = $row_sub['Items'];  
         $SubItems = $row_sub['SubItems'];
         $ItemCode = $row_sub['ItemCode'];
         $UoM = $row_sub['UoM'];
         $Class = $row_sub['Class'];
         $Description = $row_sub['Description'];
         $BINLocation = $row_sub['BINLocation'];
     
           echo "<tr>
            <td style='border: none;'>&nbsp;<input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td> 
            <!--<td style='border: none;'>&nbsp;<input type='hidden' value='$cast[$i]['id']' id='Items1' name='Items1[]'></td> -->   
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>     
            </tr>";
             
    
            
    }         
    $sql = "insert into sr_items (sr_number, Items) VALUES";
    foreach($dataArray as $row){
            $query .= '('.$row[0].',"'.$row[1].'")';
    }
    $result = mysql_query($sql, $con);
    }   
                
                   
    ?>
    </table>
    </div>
    
    <div id='RequestedBy'>
    <label>Requested By:</label>
    <select name="Requested_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ApprovedBy'>
    <label>Approved By:</label>
    <select name="Approved_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBBB'>BBBBBBBBB</option>
    <option name='CCCCCCCCCC'>CCCCCCCCCC</option>
    </select>
    </div>
    
    <div id='ReceivedBy'>
    <label>Received By:</label>
    <select name="Received_By">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id='IssuedBy'>
    <label>Issued By:</label>
    <select name="Issued BY">
    <option name='None'>Select</option>
    <option name='AAAAAAAAA'>AAAAAAAAA</option>
    <option name='BBBBBBBB'>BBBBBBBB</option>
    <option name='CCCCCCCC'>CCCCCCCC</option>
    </select>
    </div>
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onclick="save_sr()">
    </div>
    </body>
    </html>
    but no data save..what's wrong?

    I tried to save only two columns. for testing

    Thank you

  10. #10
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    Copy and paste these lines into the beginning of your PHP script:

    PHP Code:

    <?php
     $value 
    'fred';
     echo 
    __LINE__ .' : $value= ' .$value;  die;
    Output:
    3 : fred

    Once that is working then:
    1. remove the lines
    2. find the $data that you are trying to save
    3. echo the __LINE__ and the $data
    4. echo your $sql statement
    5. echo the mysql result
    6. continue stepping through the scr[pt
    7. ...
    8. ...
    I tried this :

    Code:
     $sql = "INSERT INTO stock_requisition
    (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy,
    ApprovedBy, ReceivedBy, IssuedBy)
    VALUES
    ('$sr_date', '$sr_number', '$Items1', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description',
    '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy')
    ON DUPLICATE KEY UPDATE
    sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items1', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty',
    UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy',
    ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'";  
    
    $result = mysql_query($sql, $con);  
    
    echo __LINE__ .' : $sql= ' .$sql;  die;
    no output display...

    Thank you

  11. #11
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Did you copy and paste the lines I supplied at the very top of your script and did the script show "3 fred"?
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  12. #12
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes the output is :

    173 : $value= fred

  13. #13
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to us foreach loop and array
    PHP Code:
    $Items $_GET['Items'];
    $SubItems $_GET['SubItems'];

    $sql "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom mysql_query($sql$con);

    while(
    $row mysql_fetch_assoc($res_bom)){
        
        
    $Items $row['Items'];
    echo 
    "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='
    $Items' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
            </tr>"
    ;       

    $sql "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error());


    $res_sub mysql_query($sql$con);  
     
     while(
    $row_sub mysql_fetch_array($res_sub)){
         
         
    $Items1 $row_sub['Items'];
         
    $SubItems $row_sub['SubItems'];
         
    $ItemCode $row_sub['ItemCode'];
         
    $UoM $row_sub['UoM'];
         
    $Class $row_sub['Class'];
         
    $Description $row_sub['Description'];
         
    $BINLocation $row_sub['BINLocation'];
         

         
        echo 
    "<tr>
            <td style='border: none;'>&nbsp;<input type='hidden' value='
    $Items1' id='Items1' name='Items1[]'></td>
           <!-- <td style='border: none;'>&nbsp;<input type='hidden' value='
    $cast[$i]['id']' id='Items1' name='Items1[]'></td> -->  
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems[]' value='
    $SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode[]' value='
    $ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM[]' value='
    $UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class[]' value='
    $Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description[]' value='
    $Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation[]' value='
    $BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td>     
            </tr>"
    ;
    }
     
    }   

        
    $dataArray = array(
        array(
    'Items1' => $Items),
        array(
    'SubItems' => $SubItems));           

    $sql "insert into sr_items (sr_number, Items) VALUES";
    foreach(
    $dataArray as $row){
            
    //$sql .= '('.$row[Items1].',"'.$row[SubItems].'")';
            
    $sql .= '('.$row[Items1].', '.$row[SubItems].')';
    }
    $result mysql_query($sql$con);
        
    // echo $sql;

      
    $value 'fred'
     echo 
    __LINE__ .' : $sql= ' .$sql;  die; 
    but it did not get data in while loop:

    here is the output:

    173 : $sql= insert into sr_items (sr_number, Items) VALUES(, )(, )

  14. #14
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    >>> 173 : $sql= insert into sr_items (sr_number, Items) VALUES(, )(, )

    There are no values to insert.

    Go back to just after you are declaring $dataArray and try this:

    PHP Code:

    echo count$dataArray );

    foreach( 
    $dataArray as $id => $item):
      echo 
    '<br />' .$id .' : ' $item;
    endforeach;
    die; 
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  15. #15
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code:

    Code:
        $dataArray = array(
        array('Items1' => $Items),
        array('SubItems' => $SubItems));
        
        echo count( $dataArray ); 
    
    foreach( $dataArray as $id => $item): 
      echo '<br />' .$id .' : ' . $item; 
    endforeach; 
    die;
    output:

    2
    0 : Array
    1 : Array

  16. #16
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    If you have solved your problem then please post solution for the benefit of others...

    If not then next step is to drill down and find what is in the item array:

    PHP Code:

        $dataArray 
    = array(
        array(
    'Items1' => $Items),
        array(
    'SubItems' => $SubItems));
        
        echo 
    count$dataArray ); 

    foreach( 
    $dataArray as $id => $item): 

      
    # find contents of $item array
      
    echo '<br />' .$id .' : ' print_r$item ); 

    endforeach; 
    die; 
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  17. #17
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    If you have solved your problem then please post solution for the benefit of others...

    If not then next step is to drill down and find what is in the item array:

    PHP Code:

        $dataArray 
    = array(
        array(
    'Items1' => $Items),
        array(
    'SubItems' => $SubItems));
        
        echo 
    count$dataArray ); 

    foreach( 
    $dataArray as $id => $item): 

      
    # find contents of $item array
      
    echo '<br />' .$id .' : ' print_r$item ); 

    endforeach; 
    die; 
    I tried this and the output is :

    2Array ( [Items1] => )
    0 : 1Array ( [SubItems] => )
    1 : 1

    I don't know what to do to fix my problem..

    Thank you so much

  18. #18
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Post #14
    >>> 173 : $sql= insert into sr_items (sr_number, Items) VALUES(, )(, )
    Step back though your code and find out why there are no VALUES to be inserted.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014


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
  •