Canman2005 Posted August 26, 2009 Share Posted August 26, 2009 Hi all I have a HTML form which has the following fields <input id="txtRow1" name="txtRow1" type="text"> <input id="txtRow2" name="txtRow2" type="text"> <input id="txtRow3" name="txtRow3" type="text"> <input id="txtRow4" name="txtRow4" type="text"> as you can see, the name of the field is "txtRow" followed by a number some of my pages have just 2 of the above fields and some pages have up to 45 (so going from "txtRow1" to "txtRow45"). When the form is submitted, I want to run a query for each textfield that exists. I was going to initally do if($_POST['txtRow1'] != '') { } if($_POST['txtRow2'] != '') { } if($_POST['txtRow3'] != '') { } and so on, but I think that might make my page really long and going forward some pages could have up to 120 of these textfields. Is there an easy way to do this? Hope I make some kind of sense thanks in advance everyone dave Link to comment https://forums.phpfreaks.com/topic/172021-solved-php-question/ Share on other sites More sharing options...
Alex Posted August 26, 2009 Share Posted August 26, 2009 <?php $limit = 45; for($i = 1;$i <= $limit;$i++) { if(!empty($_POST['txtRow' . $i])) { //etc.. } } ?> Link to comment https://forums.phpfreaks.com/topic/172021-solved-php-question/#findComment-907089 Share on other sites More sharing options...
Canman2005 Posted August 26, 2009 Author Share Posted August 26, 2009 pure genius AlexWD, spot on mate Link to comment https://forums.phpfreaks.com/topic/172021-solved-php-question/#findComment-907094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.