0

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!

swatch360
  • 160
  • 2
  • 15
  • 3
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – LF00 Aug 21 '19 at 09:33
  • 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` – Dhaval Purohit Aug 21 '19 at 09:42
  • This will resolve the issue I guess. – Dhaval Purohit Aug 21 '19 at 09:43
  • @DhavalPurohit this was the error thank you. please post as answer. – swatch360 Aug 21 '19 at 10:40

2 Answers2

2

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.

Dhaval Purohit
  • 1,270
  • 10
  • 28
0

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.

Pratik
  • 1,550
  • 1
  • 9
  • 9