0

Can you please help me in this context.

<form action="sample.php" method="post">
<input type="text" name="first[]" />
<input type="text" name="second[]" />
</form>

I am using this code in a loop and I need to get all the values in another page.
How can I get these value as array in another page.

4
  • So you also loop the form? Just create one form and put all generated input inside it. Commented Sep 16, 2014 at 9:16
  • "Another page?" Is this sample.php or a completely different page? What's the point of first[] and second[] in this example? Commented Sep 16, 2014 at 9:17
  • see this stackoverflow.com/questions/19022933/… Commented Sep 16, 2014 at 9:17
  • I've edit my answer below, please accept if it helped you. Commented Sep 16, 2014 at 13:43

4 Answers 4

1

you should be able to use $_POST array in the sample.php page

PHP's $_POST Array, taken from the docs:

An associative array of variables passed to the current script via the HTTP POST method.

first, add s submit button to your form, it should look like this:

<form action="sample.php" method="post">
  <input type="text" name="first[]" />
  <input type="text" name="second[]" />
  <input type="submit"> 
</form>

and in sample.php:

<?php
print_r($_POST);
?>

This is the most simple example,

once you get the hang of it, I recommend you read the docs on topics such as:

htmlspecialchars

htmlspecialchars — Convert special characters to HTML entities

Sign up to request clarification or add additional context in comments.

1 Comment

can you give an example
0

You can access it as array

$_POST['first'][0] // 0 will be index for single

to list all just loop

foreach($_POST['first'] as $first) {
     ...
}

Comments

0

Your values will end up in $_POST, and because you're using the [] syntax, you'll get an array. So, to get your first array, do:

$first = $_POST['first'];

You could then iterate over it like so:

foreach ($first as $item) {
    ...
}

Comments

-1

I think this will help you.

 $first=$_POST['first'];
  $second=$_POST['second'];
  foreach($first as $key=>$first){

   echo 'Your first value'.$first.'Your second value'.$second[$key];
}

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.