1

I would like to loop and retrieve values of multiple inputs of this form below for the best way, so how can i do, I have tried many times but unfortunately I did not succeed

here are the view code and controller code

<form action="../controller/Store/ExpensesUSD.php" method="POST">
  <div class="input-wrapper">
    <?php foreach($ExpensesUpdate AS $Expenses_Update): ?>

      <select name="ProductServiceID[]">
        <?php foreach ($expenses_registered AS $Expenses_Registered): ?>
          <option value="<?php echo $Expenses_Registered->ExpenseID; ?>">
            <?php echo $Expenses_Registered->ProductServiceName; ?>
           </option>
        <?php endforeach; ?>
      </select>

      <input type="number" name="TotalAmountUSD[]" id="TotalAmountUSD" placeholder="please enter an expense..." value="<?php echo $Expenses_Update->DeservedAmountUSD; ?>">

      <input type="hidden" name="ID[]" value="<?php echo $debts_separate->ID; ?>" readonly>

    <?php endforeach; ?>
  </div> <!-- end input-wrapper -->

  <button type="submit" name="submit" value="submit" 
 id="registerbtn">Enter</button>

</form>

$ID                     = (int)$_POST['ID'];
$ProductServiceID       = $_POST['ProductServiceID'];
$TotalAmountUSD         = $_POST['TotalAmountUSD'];
$PossibilityOFUpdating  = 'No';
$UpdatingDeletingStatus = 'Updated';
9
  • 1
    Does this answer your question? $_POST Array from html form It looks like the issue isn't that you aren't getting the values, it's that you're treating the value as an integer when what's being posted is an array of integers. $_POST['ID'] returns an array. Commented Oct 30, 2019 at 13:33
  • Properly indent your code and the problem becomes obvious. Commented Oct 30, 2019 at 13:35
  • no, my code have three different name attributes name="ProductServiceID[]" - name="TotalAmountUSD[]" - name="ID[]" Commented Oct 30, 2019 at 13:37
  • @Mohammed: What do you mean by "three different name attributes"? Any given form element can have only one name. Your multiple form values are simply being posted as arrays, aren't they? What's the specific problem? Commented Oct 30, 2019 at 13:38
  • My question is how to fetch by an array Commented Oct 30, 2019 at 13:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.