0

I am trying to get the value of the array of a html form shown below and display using php. But my code seems to have an issue.
Please assist.

html array

<textarea   rows="1"  maxlenth = "20" class="round"    id="quantityid[]" name="quantityname[]"><?php echo $itemsale["quantity"]; ?></textarea>
<td align="center"><?php echo '<span class="remove-itm"><a href="add_sales.php?saveep='.$itemsale["productname"].'&return_url='.'add_sales.php'.'"><img src="images/saveicon.png" width="30" height="30" /></a></span>'; ?></td>

<textarea   rows="1"  maxlenth = "20" class="round"    id="quantityid[]" name="quantityname[]"><?php echo $itemsale["quantity"]; ?></textarea>
<td align="center"><?php echo '<span class="remove-itm"><a href="add_sales.php?saveep='.$itemsale["productname"].'&return_url='.'add_sales.php'.'"><img src="images/saveicon.png" width="30" height="30" /></a></span>'; ?></td>

<textarea   rows="1"  maxlenth = "20" class="round"    id="quantityid[]" name="quantityname[]"><?php echo $itemsale["quantity"]; ?></textarea>
<td align="center"><?php echo '<span class="remove-itm"><a href="add_sales.php?saveep='.$itemsale["productname"].'&return_url='.'add_sales.php'.'"><img src="images/saveicon.png" width="30" height="30" /></a></span>'; ?></td>

my php code

if(isset($_GET["saveep"]) && isset($_GET["return_url"]) && isset($_SESSION["cart_sales"]))
{
    $product_code   = $_GET["saveep"]; //get the product code to remove
    $return_url     = base64_decode($_GET["return_url"]); //get return url

    foreach( $_POST['quantityname'] as $v ) {
     echo $v;
    }
}
Shaohao
  • 3,471
  • 7
  • 26
  • 45
dannjoroge
  • 608
  • 1
  • 8
  • 19

1 Answers1

0

Each element inside the form must have an unique name attribute.

Unless you treat your data to client-side to send an array, you won't be able to retrieve an array with $_POST['quantityname'].

Most likely only one field will be sent.

Check this question for a nice solution to your problem.

Community
  • 1
  • 1
caulitomaz
  • 2,141
  • 14
  • 20
  • the form auto generates itself i need help getting the values from the array – dannjoroge Jan 06 '16 at 13:57
  • Please do a `var_dump` on your `$_POST` variable and post it here, we need to check how your data is being formatted – caulitomaz Jan 06 '16 at 14:00
  • var_dump gives a null @caulitomaz – dannjoroge Jan 06 '16 at 14:05
  • Then your form / ajax request is not sending your data correctly. Please add more of your HTML (up to the form tag, submit button) and/or correspondent javascript (any $.ajax, if existent) – caulitomaz Jan 06 '16 at 15:08
  • Also, are you sure you are sending mixed GET and POST parameters at the same time? It is technically feasible, but sort of weird/confusing to do this. – caulitomaz Jan 06 '16 at 15:10