Martney Acha
Martney Acha

Reputation: 3012

How Can I Post inpputed Array Data in PHP?

I've already tried this stuff

$item=$_POST($val['item_id'])

And

$item=$_POST[$val['item_id']]

Any Idea on how to Post my inputted data ?

Upvotes: 1

Views: 65

Answers (2)

onin
onin

Reputation: 5760

1) form.html

Make sure your form uses POST method.

<form action="submit.php" method="post">
  <input name="say" value="Hi">
  <input name="to" value="Mom">
  <input type="submit" value="Submit">
</form>

2) submit.php

var_export($_POST);

Will result in:

array (
  'say' => 'Hi',
  'to' => 'Mom',
)

$_POST is not a function, but an array superglobal, which means you can access submitted data thus:

print $_POST['field_name']

Upvotes: 1

Christos Lytras
Christos Lytras

Reputation: 37337

$_POST isn't a function, it is a special PHP array that reflects the data submitted from a form. So, the second line you got there can work only if the $val['item_id'] has a valid post name key. You should always first check if that key actually exists in the $_POST data array by using isset function like this:

if (isset($_POST[$val['item_id']]) {
    $item = $_POST[$val['item_id']];
}

To debug and see all $_POST data, use this code:

<pre><?php
print_r($_POST);
?></pre>

Upvotes: 1

Related Questions