Canman2005 Posted January 22, 2010 Share Posted January 22, 2010 Hi all Wonder if anyone can help. Basically I have a bunch of form fields which look like <input name="fullname" type="text"> <input name="1-value[]" type="text" value="Apple"> <input name="4-value[]" type="text" value="Microsoft"> <input name="6-value[]" type="text" value="IBM"> <input name="12-value[]" type="text" value="1to1"> sometimes there is just 1 field, sometimes 4 fields and sometimes 20 or so fields. what I want to do is run an INSERT INTO for each form field that exists that has "-value[]" set as its "name=" tag but also, I want to be able to extract 2 things, firstly the numeric value which is defined before the "-value[]" and also the actual value of each form field (ie: IBM \ Apple). This means I would then be able to do something like INSERT INTO `items` SET `idnumber`="[b]NUMERIC VALUE[/b]", `value`="[b]FIELD VALUE (ie: IBM \ Apple)[/b]" for each form field returned. Can anyone advise? Thanks very much Link to comment https://forums.phpfreaks.com/topic/189413-foreach-using-form-field/ Share on other sites More sharing options...
The Little Guy Posted January 22, 2010 Share Posted January 22, 2010 Why don't you do this (note the input name): <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <input type="text" name="value[4]" value="Apple" /> <input type="submit" name="submit" value="Submit" /> </form> then you can do something like this: foreach($_POST['value'] as $key => $val){ mysql_query("INSERT INTO `items` SET `idnumber`='$key', `value`='$val'"); } Link to comment https://forums.phpfreaks.com/topic/189413-foreach-using-form-field/#findComment-999794 Share on other sites More sharing options...
Canman2005 Posted January 22, 2010 Author Share Posted January 22, 2010 that would be far too easy thanks man, that really helped tons, you got it spot on I can finally sleep now LOL thanks again Link to comment https://forums.phpfreaks.com/topic/189413-foreach-using-form-field/#findComment-999799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.