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.
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 withIf 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: