-1

all inputs are retrieved but unable to get the array(sp_serail[]) value when I check count using PHP I got count 1 array(sp_serail[]) count but the actual count will be 3. I can retrieve all input but the only array is not working

I tried all the possibility ($serial_no = array($_POST['sp_serail[]']); //$serial_no = array($_POST['sp_serail']);) When I submit all form data will posted I got output in google dev
tool(Network->header)->Form Data

user_id:4 bar_code: 1234 age_stock: 25 eng_stock: 12 sp_name: tst1 sp_qty: 3 sp_serail[]: 123457 sp_serail[]: 123456 sp_serail[]: 12345

<form action="issue_mat.php.php" id="Addqty" method="post">


                    <input list="eng_name" class="form-control has-feedback-left" name="eng_mobile" id="eng_mobile" placeholder="Enter Eng Mobile">

                    <span class="fa fa-file form-control-feedback left" aria-hidden="true"></span>
                  </div>
                         <div class="col-md-6 col-sm-6 col-xs-12 ">
                    <input type="text" class="form-control has-feedback-left" id="bar_code" name="bar_code" placeholder="BarCode">
                    <span class="fa fa-barcode form-control-feedback left" aria-hidden="true"></span>
                  </div>

                 <div class="col-md-3 col-sm-3 col-xs-12 ">
                    <input type="text" class="form-control" id="age_stock" name="age_stock" placeholder="WH Stock">

                  </div>

                  <div class="col-md-3 col-sm-3 col-xs-12 ">
                    <input type="text" class="form-control" id="eng_stock" name="eng_stock" placeholder="Eng Stock">
                     <input type="hidden" id="sp_name" name="sp_name" value="tst1">

                  </div>

                  <div class="col-md-6 col-sm-6 col-xs-12 ">
                    <input type="text" class="form-control" id="sp_qty" name="sp_qty" placeholder="QTY">
                     <input type="hidden" id="chk_sp_qty" name="chk_sp_qty" value="0">

                  </div>
                  <div class="col-md-6 col-sm-6 col-xs-12 ">
                       <input list="serial no." class="form-control has-feedback-left" name="add_serial" id="add_serial" placeholder="Item Serial No.">

                    <span class="fa fa-plus-square-o form-control-feedback left" aria-hidden="true"></span>
                         </div>
                      <div class="col-md-6 col-sm-6 col-xs-12" id="seral_list">
              <div class="x_panel">
                <div class="x_title">
                  <h2>Serial NO |<small>Added spare serial no.</small></h2>

                  <div class="clearfix"></div>
                </div>
                <div class="x_content">

                  <div class="">
                    <ul class="to_do" id="list_serial"><li><p>12345</p><span style="float:right; top:-20px; position: relative;"><i id="46" class="del_serial fa fa-close" style="font-size:12px;color:red"></i></span><input type="hidden" value="12345" name="sp_serail" id="sp_serail"></li><li><p>123456</p><span style="float:right; top:-20px; position: relative;"><i id="44" class="del_serial fa fa-close" style="font-size:12px;color:red"></i></span><input type="hidden" value="123456" name="sp_serail" id="sp_serail"></li>

                  </div>
                </div>
              </div>
            </div>
       <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3" id="butt_ons" style="bottom:-90px; position:relative;">

                       <button class="btn btn-primary" type="reset">Reset</button>
                       <button type="submit" id="edit" class="btn btn-success">Submit</button>

                    </div>
                  </div>

                </form>

$("#Addqty").on('submit',(function(e) {

    $("#issue_data").html('');

    e.preventDefault();
    $.ajax({
        url: "system/issue_mat.php",
        type: "POST",
        data:  new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
        success: function(data){

     $("#issue_data").html(data);

        },
        error: function(){}             
   });
}));



`if($_POST['user_id']) {
    $user_id=$_POST['user_id'];
     $bar_code=$_POST['bar_code'];
$sp_qty=$_POST['sp_qty'];
 $age_stock=$_POST['age_stock'];
$sp_name=$_POST['sp_name'];
$status=1;
$serial_no = array($_POST['sp_serail[]']);
//$serial_no = array($_POST['sp_serail']);
 $spr_count = count($serial_no);
 echo " $spr_count";


}

I want to retrieve all input with an actual array

9
  • instead of $_POST['sp_serail[]'] have you tried $_POST['sp_serail']? if my memory serves me well, it should return an array. Commented Oct 22, 2019 at 1:16
  • Possible duplicate of $_POST Array from html form Commented Oct 22, 2019 at 1:17
  • yes I tried already but still getting count 1 only Commented Oct 22, 2019 at 12:07
  • You could try var_dump($_POST) to see everything that's coming in on that POST. could be the frontend isn't sending what you expect Commented Oct 22, 2019 at 13:24
  • yes front end not sending the data but when we check with google dev.tool i got all the strings Commented Oct 23, 2019 at 0:00

2 Answers 2

0

When an input has a name like sp_serail[], PHP will put an array in $_POST['sp_serail'], it doesn't create $_POST['sp_serail[]']. So you need to do:

$serial_no = $_POST['sp_serail'];
$spr_count = count($serial_no);
Sign up to request clarification or add additional context in comments.

2 Comments

Is the misspelling serail instead of serial intentional?
intentionally var. created
0

Rectified and got the solution Removed ($serial_no = array($_POST['sp_serail[]']); //$serial_no = array($_POST['sp_serail']);) becasue array post with array only no need to convert array into array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.