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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:55:55+00:00 2026-05-27T10:55:55+00:00

I have the following code that generates my form on my html page <input

  • 0

I have the following code that generates my form on my html page

<input type="hidden" name="name[<? echo $productid; ?>]" value="<? echo     $rows["id"];?>">

                <select name="name<? echo $rows["id"];  ?>" >

                <?
                for($i = 0; $i <= sizeof($_SESSION['people']['name']); $i++){
                echo "<option>";
                echo $_SESSION['people']['name'][$i];
                echo "</option>";
                }
                echo "</select>";
                ?>

then, this form is submited to a page that is currently holding

var_dump($_POST);

and its printing out the following

array(3) { 
    ["name"]=> array(2) { 
        [2]=> string(1) "2" 
        [6]=> string(1) "6" 
    } 
    ["name2"]=> string(12) "first person" 
    ["name6"]=> string(15) "andother person" 
} 

However, as you can see, both names are being posted properly, however they are not properly associated.

string(1) is pointing to both 6 and 2. these are my product numbers and they need to be paired with a name.

can you please let me know how i can cleanup my form and properly with a a foreach loop, extract each attribute. ie the name, and the id number ( 6, 2 …)

basically, i wanna know which name is being associated with which product id number => 2, 6, etc…
i want the name to be save as $name and the id as $id.
then insert to table (name, id) values ( $name, $id)…
however, it should be in a loop to grab all of the $names and $ids.
so the first run through, it should grab “first Person and group it with 2”
2nd run through, it should grab “another person and group it with 6”

Sorry, english is not my first language. Please excuse any poor grammer.

  • 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-05-27T10:55:56+00:00Added an answer on May 27, 2026 at 10:55 am

    The string(1) bit is telling you the type of variable and length, not the key. If your arrays are related the way it looks like, you can get the info with

    foreach($_POST['name'] as $id) {
        echo $_POST['name' . $id];
    }
    

    If you plan on using any of this info with your SQL calls, be sure to sanitize the input first or you will be susceptible to SQL Injections.

    Edit:
    If you are trying to construct an id => name type array, you could do this:

    $arr = array();
    foreach($_POST['name'] as $id) {
        $arr[$id] = $_POST['name' . $id];
    }
    print_r($arr);
    //should print an array like ('2' => 'first person', '6' => 'another person')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SVG source code that generates a number of boxes with
I have following code that does not work due to a being a value
I have the following code for my login view: <?php echo $session->flash('auth'); echo $this->Form->create('User',
I have several instances of the following HTML on a page: <div class=input radio
So I have the following code that I am using to create a form
I have the following razor code: <form id=logon action=/security/dev method=get> @Html.AntiForgeryToken() @Html.EditorFor(x => x.UserName)
I have following code snippet that i use to compile class at the run
I have the following code that shows either a bug or a misunderstanding on
I have the following code that won't compile and although there is a way
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie

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.