我用 php 做了一個類似圖片中的表單,
按下加入產品按鈕就可以加入新的產品,
按下確定儲存就會存到 Mysql 數據庫。
我遇到的問題是:
在我自己本地端伺服器時執行都沒問題,
但上傳到虛擬主機商 (戰國策) 的伺服器後,
如果加入的產品數量是 77 個以上時,
按下確定儲存就會出現類似以下的錯誤訊息:
Notice: Undefined index: price in /xxx.php on line 102
Notice: Undefined index: cost in /xxx.php on line 103
Notice: Undefined index: quantity in /xxx.php on line 104
請問:
謝謝!!!
如果是上傳檔案
php.ini相關
upload_max_filesize
post_max_size
max_file_uploads
max_input_time
max_input_vars
memory_limit
mysql相關
https://stackoverflow.com/questions/3536103/mysql-how-many-rows-can-i-insert-in-one-single-insert-statement
蠻多都有關係的
但是看你的情況應該是code沒寫好而已
看你要不要貼code吧
firecold 大大:
查看虛擬主機商的 php 設置後,
發現 max_input_vars 最大為 1000 個,
測試了一下,確定問題是表單送出的數量超過 1000 個。
我設置了 .htaccess 文件,
下面的寫法無效,還是會錯誤:
php_value max_input_vars 5000
請問還有什麼方式可以更改 max_input_vars 的設定嗎?
是否必須要請虛擬主機商幫我改呢?
我推測試code的問題,方便提供code嘛
77筆你範例的資料不太可能是ini的問題
firecold 大大:
抱歉沒有說明清楚,
我圖片的範例是簡化過的,
實際上的表單是如下:
<form action='' method='POST'>
<table class='formTable_01'>
<tr>
<th>採購單日期</th>
<td><input type='text' name='datepicker' value='<?php echo $formItems['datepicker']; ?>' id='datepicker' /></td>
</tr>
<tr>
<th>供應商</th>
<td><?php echo $supplierSelectOption; ?></td>
</tr>
<tr>
<th>匯率</th>
<td><input type='text' name='exchange_rate' value='<?php echo $exchange_rate; ?>' id='exchange_rate' class='isNumber' /></td>
</tr>
</table>
<table class='formTable_02'>
<tr>
<th>採購單編號</th>
<td>
<?php
echo "
{$formItems['purchase_number']}
<input type='hidden' name='purchase_number' value='{$formItems['purchase_number']}' />
";
?>
</td>
</tr>
<tr>
<th>總標準成本</th>
<td class='bgBlue'>
<?php
echo "
{$cost_standard_total}
<input type='hidden' name='cost_standard_total' value='{$cost_standard_total}' id='cost_standard_total' />
";
?>
</td>
</tr>
<tr>
<th>總採購成本</th>
<td class='bgYellow'>
<?php
echo "
{$cost_original_total}
<input type='hidden' name='cost_original_total' value='{$cost_original_total}' id='cost_original_total' />
";
?>
</td>
</tr>
</table>
<div class='spacing'></div>
<table class='formTable_03'>
<tr>
<td colspan='20'>
<?php echo $viewer->getAddProductsSubmit(); ?>
</td>
</tr>
<tr>
<th>產品代碼</th>
<th>產品名稱</th>
<th>零售價</th>
<th class='w7em'>標準外幣</th>
<th class='w7em'>標準成本</th>
<th class='w7em'>採購外幣</th>
<th class='w7em'>採購成本</th>
<th class='w8em'>折數</th>
<th class='w9em'>採購量</th>
<th class='w9em'>標準成本小計</th>
<th class='w9em'>採購成本小計</th>
<th>移除</th>
</tr>
<?php
if (isset($formItems['products'])) {
$products = $formItems['products'];
foreach ($products as $x=>$y) {
// 格式化小數點
$price = $formatDecimal->setPrice($y['price']);
$foreign_standard = $formatDecimal->setPurchaseMoney($y['foreign_standard']);
$cost_standard = $formatDecimal->setPurchaseMoney($y['cost_standard']);
$foreign_original = $formatDecimal->setPurchaseMoney($y['foreign_original']);
$cost_original = $formatDecimal->setPurchaseMoney($y['cost_original']);
$discount = $formatDecimal->setDiscount($y['discount']);
$purchase_quantity = $formatDecimal->setQuantity($y['purchase_quantity']);
$item_total_cost_standard = $formatDecimal->setPurchaseMoney($y['item_total_cost_standard']);
$item_total_cost_original = $formatDecimal->setPurchaseMoney($y['item_total_cost_original']);
$theBoolean = $model->canRemove($y['purchase_item_id']);
$remove = $viewer->getRemove($y['purchase_item_id'], $theBoolean);
echo "
<tr>
<td>
{$y['brand_product_number']}
<input type='hidden' name='products[{$x}][purchase_item_id]' value='{$y['purchase_item_id']}' />
<input type='hidden' name='products[{$x}][product_id]' value='{$y['product_id']}' />
<input type='hidden' name='products[{$x}][brand_product_number]' value='{$y['brand_product_number']}' />
</td>
<td>
{$y['full_product_name']}
<input type='hidden' name='products[{$x}][full_product_name]' value='{$y['full_product_name']}' />
</td>
<td class='alignRight'>
{$price}
<input type='hidden' name='products[{$x}][price]' value='{$price}' />
</td>
<td class='bgBlue'>
<input type='text' name='products[{$x}][foreign_standard]' value='{$foreign_standard}' class='alignRight isNumber foreign_standard' />
</td>
<td class='alignRight bgBlue'>
{$cost_standard}
<input type='hidden' name='products[{$x}][cost_standard]' value='{$cost_standard}' class='cost_standard' />
</td>
<td class='bgYellow'>
<input type='text' name='products[{$x}][foreign_original]' value='{$foreign_original}' class='alignRight isNumber foreign_original' />
</td>
<td class='alignRight bgYellow'>
{$cost_original}
<input type='hidden' name='products[{$x}][cost_original]' value='{$cost_original}' class='cost_original' />
</td>
<td class='alignRight'>
{$discount}
%
<input type='hidden' name='products[{$x}][discount]' value='{$discount}' class='discount' />
</td>
<td>
<input type='text' name='products[{$x}][purchase_quantity]' value='{$purchase_quantity}' class='alignRight isNumber purchase_quantity' />
</td>
<td class='alignRight bgBlue'>
{$item_total_cost_standard}
<input type='hidden' name='products[{$x}][item_total_cost_standard]' value='{$item_total_cost_standard}' class='item_total_cost_standard' />
</td>
<td class='alignRight bgYellow'>
{$item_total_cost_original}
<input type='hidden' name='products[{$x}][item_total_cost_original]' value='{$item_total_cost_original}' class='item_total_cost_original' />
</td>
<td>
{$remove}
</td>
</tr>
";
}
}
?>
<tr>
<td colspan='20'>
備註:
<textarea name='remark'><?php echo $formItems['remark']; ?></textarea>
</td>
</tr>
</table>
<?php
echo $viewer->getRemoveList($formItems);
echo $viewer->getConfirmSubmitInBox();
?>
</form>
每一個產品會有 13 個 input,
76 個產品總共會送出 988 個,
加上其他單獨的幾個 input,
送出的數量差不多是 1000 個。
然後我測試把每個產品刪除二個欄位,變成 11 個 input,
結果可以送出 90 個產品,
所以我想應該就是 max_input_vars 的問題了。
只是我沒辦法自己更改設置 ...
PHP Notice 而已,
在程式碼起始點加上這行就好!
error_reporting(E_ALL ^ E_NOTICE);
讓 Notice 不要印…