limitphp Posted April 14, 2009 Share Posted April 14, 2009 I have a form that will submit x number of people. textboxes: name=fname[] name=lname[] name=position[] The x could be 1 person, 2 or 7 people, etc.... I'll have that number sent in the form also via a textbox name=num For each person I'll need to add their fname, lname and position to a database. How can I process this form as an array? I could do the: foreach($_POST['fname'] AS $fname) echo $fname; but then I'd have to do that loop for each item....fname, lname and position....is there a more effiecient way? thanks Quote Link to comment https://forums.phpfreaks.com/topic/154071-solved-help-processing-form-values-as-array/ Share on other sites More sharing options...
JonnoTheDev Posted April 14, 2009 Share Posted April 14, 2009 Yes using one loop not 3. You must make sure that all arrays are of the same size for($x = 0; $x < count($_POST['fname']); $x++) { mysql_query("INSERT INTO table SET fname='".mysql_real_escape_string($_POST['fname'][$x])."', lname='".mysql_real_escape_string($_POST['lname'][$x])."', position='".mysql_real_escape_string($_POST['position'][$x])."'"); } Quote Link to comment https://forums.phpfreaks.com/topic/154071-solved-help-processing-form-values-as-array/#findComment-809877 Share on other sites More sharing options...
limitphp Posted April 14, 2009 Author Share Posted April 14, 2009 thanks Quote Link to comment https://forums.phpfreaks.com/topic/154071-solved-help-processing-form-values-as-array/#findComment-809898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.