【问题标题】:multiple row php mysql insert多行php mysql插入
【发布时间】:2015-03-08 10:09:22
【问题描述】:

这段代码需要一个 save.php 文件来插入表单中的数据。我不知道如何为数组创建一个循环。

<!-- Begin page content -->
<div class="container content">

    <div class='row'>
        <div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th width="2%"><input id="check_all" class="formcontrol" type="checkbox"/></th>
                        <th width="15%">Model Code</th>
                        <th width="30%">Brand</th>
                        <th width="30%">Description</th>
                        <th width="15%">Model Num</th>
          <th width="15%">Serial Number</th>
          <th width="30%">Color</th>
          <th width="40%">Unit Cost</th>
          <th width="15%">Selling Price</th>

          <th width="25%">Interest Rate</th>
          <!-- 
          ITEM NO/product Code - model code
          ITEM NAME/product Name - brand
          PRICE - description
          QUANTITY - modelnum
           -->
                    </tr>
                </thead>
        <form id="SignupForm" method="post" action="saveStocks.php">
                <tbody>
                    <tr>
            <td><input class="case" type="checkbox"/></td>
            <td><input type="text" data-type="modelCode" name="modelCode[]" id="modelCode_1" class="form-control autocomplete_txt" autocomplete="off"></td>
            <td><input type="text" data-type="brand" name="brand[]" id="brand_1" class="form-control autocomplete_txt" autocomplete="off"></td>
            <td><input type="text" name="description[]" id="description_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
            <td><input type="number" name="modelNum[]" id="modelNum_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
            <td><input type="number" name="srp[]" id="srp_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>

            <td><input type="number" name="color[]" id="color_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>

            <td><input type="number" name="untiCost[]" id="unitCost_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>

            <td><input type="number" name="serialNumber[]" id="serialNumber_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
            <td><select type="number" name="intRate[]" id="intRate_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;">
                <option></option>
                <option value="1">0.01</option>
                <option value="2">0.05</option>
                </select></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class='row'>
        <div class='col-xs-12 col-sm-3 col-md-3 col-lg-3'>
            <button class="btn btn-danger delete" type="button">- Delete</button>
            <button class="btn btn-success addmore" type="button">+ Add More</button>
       </div>
       <input type="submit" id="SaveAccount" value="Save Stocks">
        <div class='col-xs-12 col-sm-offset-4 col-md-offset-4 col-lg-offset-4 col-sm-5 col-md-5 col-lg-5'>
        </div>
    </div>  
</div>
<h2>&nbsp;</h2>


<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/auto.js"></script>

需要存档码

Git 代码表单 smarttutorials.net,我需要一个 .php 文件来保存或插入表单中的数据。我不知道从哪里开始。有什么想法吗?

【问题讨论】:

标签: javascript php arrays


【解决方案1】:

我想你的问题是如何循环通过表单传递到 savestocks.php 的数据。

在这种情况下,$_POST 会为您提供传递的值名称对的数组。所以它可能是这样的:

foreach ($_POST as $key=>$value){
  .... here do you processing.....
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-25
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2022-01-17
    • 2018-04-19
    相关资源
    最近更新 更多