nevsi79 Posted March 16, 2008 Share Posted March 16, 2008 my script worked, i was jumping on my bed with joy, then I modified and now it does not work I just can't see why?!!! here's my form: http://geeks-fix.co.uk/wforms/form.html now this is my code: <?php $cnt = count($_POST['wf_Relatives1']); // any field that //repeats(if you want to know how many repeats there are) $fieldset = $_POST['wf_Relatives1']; $field = $_POST['wf_FirstName']; //echo "$field"; $field2 =$_POST['wf_LastName']; //echo "$field"; $field3 =$_POST['wf_BirthDate2']; //echo "$field"; foreach ($fieldset as $c) { while (list($k, $v) = ($c)) { echo "$k ... $v <br/>"; } } ?> The first time it worked definitely with the $fieldset and after I added 3 times (first name, last name, dob) in the form, it did output the following: 0 ... some first name A 1 ... some first name B 2 ... some first name C 0 ... some last name A 1 ... some last name B 2 ... some last name C 0 ... some dob A 1 ... some dob B 2 ... some dob C but now it is not working, instead prints out this: Warning: Invalid argument supplied for foreach() in /home2/nevsi79/public_html/wforms/firstoutput.php on line 15 Can anyone see where the problem is: I wonder how they are doing it here: http://www.formassembly.com/wForms/v2.0/documentation/examples/repeat.html Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 16, 2008 Share Posted March 16, 2008 Foreach expects an array. You're giving it a string. Quote Link to comment Share on other sites More sharing options...
nevsi79 Posted March 16, 2008 Author Share Posted March 16, 2008 Foreach expects an array. You're giving it a string. Yes but it worked the first time, I found this in my book: foreach ($fieldset as $c) { while(list($k, $v) = each ($c)) { echo "k ... $v <br/>"; } } Anyhow, you might understand me better if I do the following (print_r the fields as they are arrays even if I do not repeat them with the repeat js behaviour as I added [] to the names of each field): <?php $cnt = count($_POST['wf_Relatives1']); // any field that //repeats(if you want to know how many repeats there are) $fieldset = $_POST['wf_Relatives1']; $field = $_POST['wf_FirstName']; print_r($field); echo"<br/>"; $field2 =$_POST['wf_LastName']; print_r($field2); echo"<br/>"; $field3 =$_POST['wf_BirthDate2']; print_r($field3); echo"<br/>"; //foreach ($fieldset as $c) { //while(list($k, $v) = each ($c)) { //echo "k ... $v <br/>"; //} //} ?> and then I get this output: Array ( [0] => some first name A [1] => some first name B [2] => some first name C ) Array ( [0] => some last name A [1] => some last name B [2] => some last name C ) Array ( [0] => some DOB A [1] => some DOB B [2] => some DOB C ) I do not insist in organising them in a multidimensional array, but my final go is t put them in mysql table. MySql table will basically have 3 columns: first name, last name, DOB and I want A, B & C to be different entries i.e. rows in my table, if that makes sense at all? Can anyone help, please? Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 16, 2008 Share Posted March 16, 2008 You didn't print_r the feildset variable... which happens to be the one you need to be an array, or foreach returns an error. Quote Link to comment Share on other sites More sharing options...
nevsi79 Posted March 16, 2008 Author Share Posted March 16, 2008 no it didn't work with print_r($fieldset) it did work with my foreach earlier I was so happy, jumping on my bed with joy and then I messed it up, can't even see why Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 16, 2008 Share Posted March 16, 2008 that's your problem. For some reason, $fieldset is no longer an array, so your call to foreach($fieldset... returns an error Quote Link to comment 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.