Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:55:48+00:00 2026-06-16T00:55:48+00:00

I have user inputs as follows: <form action=special.php method=post> <input name=first1> <input name=last1> <input

  • 0

I have user inputs as follows:

<form action="special.php" method="post">
    <input name="first1"> <input name="last1"> <input name="age1">
    <input name="first2"> <input name="last2"> <input name="age2">
    <input name="first3"> <input name="last3"> <input name="age3">
    <input name="first4"> <input name="last4"> <input name="age4">
    <input name="first5"> <input name="last5"> <input name="age5">
    <input name="first6"> <input name="last6"> <input name="age6">
    ...

    N
</form>

The amount of user inputs in the form is determined by the user; meaning, the user can add 5,10,20 additional lines to the code above, creating new input elements (following the pattern above) as they fit.

My question is, once the form gets submitted, what is an easy way to iterate and print out all the SET POST variables?

Something like:

for($i=0; $i < $numPostVars; $i++){
   if(isset($_POST['first".$i."'])){
       //echo all first names post variables that are set
    }
}

// do the same from last names & age in separate loops
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:55:49+00:00Added an answer on June 16, 2026 at 12:55 am

    Inputs can be treated as arrays with a syntax very similar to that used in PHP:

    <input name="name[1]" value="value 1">
    <input name="name[2]" value="value 2">
    

    This would result in a $_POST['name'] that looks like this:

    array(
      1 => "value 1",
      2 => "value 2"
    );
    

    This principle can be expanded to incorporate multi-dimensional and associative arrays. So if you were to name your inputs like this:

    <input name="rows[1][first]"> <input name="rows[1][last]"> <input name="rows[1][age]">
    <input name="rows[2][first]"> <input name="rows[2][last]"> <input name="rows[2][age]">
    

    …you would be able to easily iterate over $_POST['rows'] with a foreach construct. The data structure will be very similar to a set of database results.

    foreach ($_POST['rows'] as $row) {
      // do stuff with $row['first'], $row['last'] and $row['age'] here
    }
    

    A couple of things to note:

    • Unlike PHP, associative array keys in HTML do not require quotes, and using them will produce a result you may not expect. It will work, but not in the way you might think. You still need to use quotes in PHP though.
    • As far as I am aware, this syntax is not a W3C standard. PHP, however, always handles it as expected.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML form as follows: <form enctype="multipart/form-data" action=" " method="post"> <input name="username"
I have a simple form like: <form action= method=post> <input type=text name=user id=user class=txt
I have a Submit button to remove a user: <form class=spform action=<?=$_SERVER['PHP_SELF']?> method=post name=userdetails
<form class=follow-form method=post action=listen.php> <input name=followID value=123456 type=hidden> <button type=submit value=Actions class=btn follow title=123456>
I have a form and one of my inputs lets my user input their
I have a page that allows for used input, when the user inputs his/her
I have a login form that has Username and password as inputs from user
I got two simple input text fields in a HTML form: <input type=text name=data[User][name]
I want to let user input two variable, Name and Password in a form.
I have a form in a JSP as follows: <form action = <c:url value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.