Reputation: 180
The problem is when i am adding the more than 624 stickers.
The code works fine when the stickers are less than 624. it seems to not allow for more stickers.
I seem to be having a strange error that i cant fix.
the error i keep getting is: Undefined offset: 624
this is what i have:
php:
//product names
for ($x = 0; $x < $counter; $x++) {
$product[] = $_POST["product_name"][$x];
$product_price[] = preg_replace('/\s+/', '', $_POST["product_price"][$x]);
$product_barcode[] = preg_replace('/\s+/', '', $_POST["product_barcode"][$x]);
$product_stickers[] = preg_replace('/\s+/', '', $_POST["product_stickers"][$x]);
$vendor_code[] = $result = $this->getUsername($user_id, $x);
}
$result = array();
$values = array($product, $product_price, $product_barcode, $vendor_code, $product_stickers);
//$values = array($product, $product_price, $product_barcode, $vendor_code);
foreach ($products as $index => $key) {
$t = array();
foreach ($values as $value) {
$t[] = $value[$index];
}
$result[$key] = $t;
}
$products_json = json_encode($result);
html:
@for($x = 0; $x <= 650; $x++)
<tr>
<td><input type="text" name="product_name[]" class="product_name"
value="{{$x}}"></td>
<td><input type="text" name="product_price[]" class="product_price"
value="{{$x}}"></td>
<td><input type="text" name="product_barcode[]"
class="product_barcode"
value="{{$x}}"></td>
<td><input type="text" name="product_stickers[]"
class="product_stickers"
value="{{$x}}"></td>
<td><a role="button" style="color:#fff" class="delRowBtn btn btn-
warning">Remove</a>
</td>
</tr>
@endfor
im not sure why it is not working for adding more than 624 stickers please help!
Upvotes: 0
Views: 73
Reputation: 1290
It is may be you are posting more data then it's allowed in php.ini
eg. increase post_max_size
and max_input_vars
This will resolve the issue I guess.
Upvotes: 2
Reputation: 1550
It is may be you are posting more data then it's allowed in php.ini eg. increase post_max_size and max_input_vars .. if everything in code you are sure...
Always check existence of variable before use, specially when it is in dynamic array. Possible issue: 1. index start from 1 and in loop starts from 0 2. Object fetched before it was assign. However,
$product[] = $_POST["product_name"][$x] ?? null;
or
$product[] = (!empty($_POST["product_name"][$x])) ? $_POST["product_name"][$x] : null;
put conditions before use. all places where dynamic key is generated for array to rid-off errors.
Upvotes: 0