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

  • Home
  • SEARCH
  • 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 8251889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:23:07+00:00 2026-06-08T00:23:07+00:00

I am trying to get information from an html form and pass it to

  • 0

I am trying to get information from an html form and pass it to my php file as an array

here is a snippet of the code for my html form:

<form action ="upload.php" method="post">
    Name<input id= "n" type="text" name="info[name]" /><br />
    Address: <input id="a" type = "text" name="info[address]" /><br />
    City: <input id="c" type = "text" name="info[city]" /><br />
</form>

then in my php file I tried to print the content:

$information = $_POST['info'];

echo $information['name'];

but nothing gets printed to the page

  • 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-08T00:23:08+00:00Added an answer on June 8, 2026 at 12:23 am

    I don’t think you can do that (shove it all into a separate array (apart from $_POST)) directly with your HTML. You’ll have to do some extra PHP work at the beginning.

    Firstly, for the love of all that is holy, make your HTML input names cleaner:

    <form action ="upload.php" method="post">
    Name<input id= "n" type="text" name="info_name" /><br />
    Address: <input id="a" type = "text" name="info_address" /><br />
    City: <input id="c" type = "text" name="info_city" /><br />
    </form>
    

    And now, for the PHP:

    //this is how I would do it, simply because I don't like a bunch of if/elseifs everywhere..
    //define all the keys (html input names) into a single array:
    $infoKeys[0]='name';
    $infoKeys[1]='address';
    $infoKeys[2]='city';
    //define your end array
    $information=array();
    //now loop through them all and if they're set, assign them to an array. Simple:
    foreach ( $infoKeys as $val ){
    
    if(isset($_POST['info_'.$val])){
    
    $information[$val]=$_POST['info_'.$val];
    
    }//end of isset
    
    else{
    
    $information[$val]=null;
    
    }//end of no set (isset===false)
    
    }//end of foreach
    
    //now, when you want to add more input names, just add them to $inputKeys. 
    //If you used the if/elseif ways, your doc would be plastered in ifs and elseifs. 
    //So i personally think the looping through the array thing is neater and better. 
    //but, feel free to change it, as I have a feeling I'll have allot of critics because of this method.
    
    // anyway, that should do it. The var $information should be an array of all your 'info_' html inputs....
    

    Happy coding!

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

Sidebar

Related Questions

I'm trying to have an array display information inputted from a PHP-created HTML form.
Hi I am trying to get information on an Oracle package directly from PHP
So what I'm trying to do here is to pass information from a input
I have been trying to get a form in HTML/PHP to process to into
I have a form that I'm trying to get information from the user when
I am trying to get info from the html form from my servlet. My
How can I store information in a array? I'm trying to get information from
I'm trying to get information from this site: http://www.gocrimson.com/sports/mbkb/2011-12/roster If you look at that
I'm trying to get information from a cookie into Alfresco Share. I have a
i have two tables i am trying to get information from. login table -

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.