我將打開對話框中的資料作為tdname[rowid]. 我得到的結果如下。
<form method="post" id="user_form">
<div class="table-responsive">
<table id="user_data">
<tbody>
<tr id="row_1">
<td>1 <input type="hidden" name="hidden_pid[]" id="pid1" class="pid" value="1"></td>
<td>K-60 <input type="hidden" name="hidden_p_code[]" id="p_code1" class="p_code" value="K-60"></td>
<td>Product 1<input type="hidden" name="hidden_p_name[]" id="p_name1" value="Product 1"></td>
<td> <input type="hidden" name="hidden_dekorA[]" id="dekorA1" value=""></td>
<td class="p_quantity">1 <input type="hidden" name="hidden_p_quantity[]" class="p_quantity1" id="p_quantity1" min="0" max="2500" step="1" value="1" data-type="1"></td>
<td>23.40 <input type="hidden" name="hidden_p_listprice[]" class="p_listprice1" id="p_listprice1" value="23.40" data-type="23.40"></td>
<td>23.40 <input type="hidden" name="hidden_p_netprice[]" id="p_netprice1" value="23.40"></td>
<td class="p_total">23.40 <input type="hidden" name="hidden_p_total[]" class="p_total" id="p_total1" value="23.40" for="1"></td>
<td>122 <input type="hidden" name="hidden_preorderno[]" id="preorderno1" class="preorderno" value="122"></td>
</tr>
.
.
.
</tbody></table>
</div>
<div align="center">
<button type="submit" name="insert" id="insert" class="btn btn-primary">Confirm Order</button>
</div>
</form>
insert.php然后我使用 ajax post 方法將資料發送到檔案。
<script>
$(document).ready(function(){
$('#user_form').on('submit', function(event){
event.preventDefault();
var form_data = $("[name='hidden_pid[]'],[name='hidden_p_code[]'],[name='hidden_p_name[]'],[name='hidden_dekorA[]'],[name='hidden_p_quantity[]'],[name='hidden_p_listprice[]'],[name='hidden_p_netprice[]'],[name='hidden_p_total[]'],[name='hidden_preorderno[]']").serialize();
$.ajax({
type:"POST",
url:"insert.php",
data : (form_data),
success:function(data)
{
alert('OK');
},
error:function(data){
alert('hata');
}
});
});
});
</script>
我不想序列化所有專案,所以這就是為什么我使用這樣的序列化 =>[name='hidden_pid[]']
我使用存盤程序進行插入。NEWLIST 是我的插入程式。
Insert.php檔案:
$db = new PDO("mysql:host=localhost;dbname=;charset=utf8;","username","pass");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$sp='NEWLIST';
$sql=sprintf('SELECT group_concat(DISTINCT ":",`parameter_name`) as `placeholders` FROM `information_schema`.`parameters` WHERE `SPECIFIC_NAME`="%s" and `specific_schema`="wpdb"', $sp);
$res=$db->query($sql)->fetch(PDO::FETCH_OBJ);
$placeholders=$res->placeholders;
$sql=sprintf('call `%s`( %s );', $sp, $placeholders);
$keys=explode( ',', $placeholders );
$size = count($_REQUEST['hidden_pid']);
$count = 0;
$stmt=$db->prepare($sql);
while($count < $size){
$main_arr = array(
':pid' => $_REQUEST['hidden_pid'][$count],
':p_code' => $_REQUEST['hidden_p_code'][$count],
':p_name' => $_REQUEST['hidden_p_name'][$count],
':dekorA' => $_REQUEST['hidden_dekorA'][$count],
':p_quantity' => $_REQUEST['hidden_p_quantity'][$count],
':p_listprice' => $_REQUEST['hidden_p_listprice'][$count],
':p_netprice' => $_REQUEST['hidden_p_netprice'][$count],
':p_total' => $_REQUEST['hidden_p_total'][$count],
':preorderno' => $_REQUEST['hidden_preorderno'][$count],
':yetkili' => $_SESSION['id']
);
$count ;
$data=array_combine($keys, array_values($main_arr));
$stmt->execute($data);
}
$db->commit();
} catch( PDOException $e ){
return "Insert failed: " . $e->getMessage();
}
$db = null;
這是有效的。但問題是我可以像這樣向mysql最多插入111行。我在表單和 ajax 上添加數百行發送值到 insert.php 但 insert.php 最多向 mysql 插入 111 行。我還研究了stackoverflow,人們說max_allowed_packet值應該是500MB。我已經這樣做了。但仍在討論這個問題。問題出在insert.php我想。但是我怎么能解決這個我不知道的問題。我想看看你的幫助..
它不適用于我的兩臺服務器:
1.測驗服務器資訊
CPU:AMD 銳龍 7 2700,3.2 GHz
記憶體:16 GB 記憶體
2.樹莓派4服務器資訊
CPU:BCM2711,1.5 GHz
記憶體:4 GB 記憶體
uj5u.com熱心網友回復:
您需要增加 .php 中的 PHP[ max_input_vars] 設定php.ini。默認值為 1,000。每行有 9 個引數,即只允許 111 行。
將您需要支持的最大行數乘以 9 并將其設定為高于此值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/503872.html
