For each? Loop? Many Form Fields with DB insert

C++, C#, Java, PHP, ect...
Post Reply
Com4dor
Posts: 12
Joined: Sat Apr 19, 2014 10:46 pm

For each? Loop? Many Form Fields with DB insert

Post by Com4dor »

...form data...

So basically I have it set up so on the click of a button I can add more fields to the current form. Example: Multiple drops (of items) from chopping a tree.

echo "<table><tr><td>Drops: <select name=\"input4-a[]\" id=\"items\">";
echo $items;
echo "</select> </td>";

echo "<td>[Chance: <input type=\"text\" name=\"input4-b\" style=\"width:80px;\" value=\"30 / 3000\"/> ]</td></tr></table>";

So its basically there so I can add many drops to the chopping a tree.

What I need is to collect the values from input4-a and input4-b so I can insert the data ($_POST[input4-a] & $_POST[input4-b]) into the drops table.

Any ideas?
Just follow your arrow wherever it points
Com4dor
Posts: 12
Joined: Sat Apr 19, 2014 10:46 pm

Re: For each? Loop? Many Form Fields with DB insert

Post by Com4dor »

It's like this But I need id1 and id2 and then they need to get inserted into the same Drops table.

Image
Just follow your arrow wherever it points
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: For each? Loop? Many Form Fields with DB insert

Post by hallsofvallhalla »

not sure exactly what you are going for but

Code: Select all

document.getElementById("id" + $key).value
Com4dor
Posts: 12
Joined: Sat Apr 19, 2014 10:46 pm

Re: For each? Loop? Many Form Fields with DB insert

Post by Com4dor »

I managed to find this online somewhere and worked out for me! Here's what I used in case someone else comes across this.

Code: Select all

for ($i=0; $i < count($_POST['id']); $i++) {
$drop_id = $_POST['id'][$i]; 
$drop_chance = $_POST['id2'][$i]; 

//Insert Query
}
Just follow your arrow wherever it points
Post Reply

Return to “Coding”