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 8540985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:43:25+00:00 2026-06-11T11:43:25+00:00

I have a form that has two field inputs that also have the same

  • 0

I have a form that has two field inputs that also have the same name “name”

I was wondering what do I have to do , to capture both fields in array,

for example, if field1 get post and field2 was empty, I would like to get an array[0]
with the data I was looking for and if field1 and field2 where submited, I would like to have array[0] and array[1] populated.

currently the form I have will only capture if both fields are populated and if one of them is populated it wonn’t capture .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>


<?php 

$name=$_POST['name'];


if($name)
{

    echo $name;

    }


?>


</head>

<body>


<form action="<?php $_SERVER['PHP_SELF']?>" method="post">

  <p>name
  <input name="name" id="name" type="text" />



  </p>
  Name

  <input name="name"  id="name" type="text" />
  <p>&nbsp;</p>


  <input name="submit" type="submit" />
</form>
</body>
</html>

I would like the end results for the variable name to be an array that would have both data that was capture from field one and field two.

thanks

  • 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-11T11:43:26+00:00Added an answer on June 11, 2026 at 11:43 am

    Change the name of each field to name[], then they can be accessed in PHP using $_POST['name'][0] and $_POST['name'][1].

    EDIT: You can also use name[1] in your HTML to explicitly set indices, or even name[foo], then access from PHP using $_POST['name']['foo'].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that has 3 types of field: (2) text fields that
I have a form that has a group of 3 text_fields. I need two
I have a form that has two buttons on it, one yes, one no,
I have a windows form that has two DataGridViews (DGVs) that will hold 25,000+
I'm creating a form that has two checkboxes yes and no. I have added
I have a view that has two buttons(First and Second) and one hidden field.
I have a index.jsp file that has two different types of forms <form action=searchpath
I have a form with a table that has two input boxes, a select
My code has two forms that create a text field for both username and
I have created a dynamic form using jQuery that has two sections, once the

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.