这是我的PHP代码,我试图在第一个字段中插入“ confirmMasterId”
  但是当我尝试插入记录时,仅在第一条记录中使用confirmMasterId

this is hidden value which i am trying to insert in 1st field

<input type="hidden" value={$confirmMasterId} name="confirmMasterId[]">

  $loopCount = 0;
   while($loopCount < count($_POST['itemId']))
   {

     $confirmMasterId          = isset($_POST['confirmMasterId'][$loopCount]) && ($_POST['confirmMasterId'][$loopCount] != '') ? $_POST['confirmMasterId'][$loopCount] : 0;
     $itemId          = isset($_POST['itemId'][$loopCount]) && ($_POST['itemId'][$loopCount] != '') ? $_POST['itemId'][$loopCount] : 0;
     $itemCode        = isset($_POST['itemCode'][$loopCount]) && ($_POST['itemCode'][$loopCount] != '') ? $_POST['itemCode'][$loopCount] : 0;
     $cDetailDate     = isset($_POST['cDetailDate'][$loopCount]) && ($_POST['cDetailDate'][$loopCount] != '') ? $_POST['cDetailDate'][$loopCount] : 0000-00-00;
     $quantity        = isset($_POST['qty'][$loopCount]) && ($_POST['qty'][$loopCount] != '') ? $_POST['qty'][$loopCount] : 0;
     $partyDetail     = isset($_POST['partyDetail'][$loopCount]) && ($_POST['partyDetail'][$loopCount] != '') ? $_POST['partyDetail'][$loopCount] : 0;
     $rs              = isset($_POST['rs'][$loopCount]) && ($_POST['rs'][$loopCount] != '') ? $_POST['rs'][$loopCount] : 0;
     $tax             = isset($_POST['tax'][$loopCount]) && ($_POST['tax'][$loopCount] != '') ? $_POST['tax'][$loopCount] : 0;
     $vat             = isset($_POST['vat'][$loopCount]) && ($_POST['vat'][$loopCount] != '') ? $_POST['vat'][$loopCount] : 0;
     $totalRs         = isset($_POST['totalRs'][$loopCount]) && ($_POST['totalRs'][$loopCount] != '') ? $_POST['totalRs'][$loopCount] : 0;


     $plusMinus = '-';
     if($_POST['qty'][$loopCount] != "" && $_POST['qty'][$loopCount] > 0)
     {
      echo"<br>".$detailQuery = "INSERT INTO confirmmasterdetail (confirmMasterId,itemId,cDetailDate,qty,partyId,rs,tax,vat,totalRs)
                                           VALUES (".$confirmMasterId.",".$itemId.",'".$cDetailDate."',
                                                   ".$quantity.",".$partyDetail.",".$rs.",".$tax.",".$vat.",".$totalRs.")";
       $detailQueryRes = mysql_query($detailQuery);
       insertItemStock($itemId,$quantity,$plusMinus,$itemCode);
     }
     $loopCount++;
     $selectTotal  = "SELECT totalAmount
                        FROM confirmmaster
                      WHERE quotationMasterId  = ".$_POST['quotationMasterId'];
     $selectTotalRes = mysql_query($selectTotal);
     if($totalRow = mysql_fetch_array($selectTotalRes))
     {
       $totalAmount = $totalRow['totalAmount'];
     }
   }

最佳答案

因此,如果您只有一种价值,那为什么呢?

$confirmMasterId = isset($_POST['confirmMasterId'][$loopCount]) && ($_POST['confirmMasterId'][$loopCount] != '') ? $_POST['confirmMasterId'][$loopCount] : 0;

您应该使用相同的值(如果您的意思是所有记录都相同):

$confirmMasterId = isset($_POST['confirmMasterId'][0]) && ($_POST['confirmMasterId'][0] != '') ? $_POST['confirmMasterId'][0] : 0;

您甚至可以在循环之前准备该值:-)

关于php - 隐藏的ID未插入到while循环中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28722538/

10-10 05:25