dooh Posted November 14, 2007 Share Posted November 14, 2007 Hello, I am posting numbers. the name = number for all names = ...and the value = different numbers eg...fx1005 or dx33 or sx9 the fx, dx, sx is just added to the number and it tells me what to do with the value when I get it here is the code I wrote to get the values back: $numbers_received = array(); $numsA = array(); $counter = 0; $numbers_received = $_POST['number']; foreach($numbers_received as $value) { $numsA[$counter] = "$value"; $counter = $counter + 1; } and now to look at what I received.. echo $numsA[4]; I get this error in the log: invalid argument supplied foreach() It leads me to believe that what was posted was not an array. Is this true? Is there a way for me to do this? This was just a test sending 10 numbers and I had hoped that it would echo a result..it did not I can do this a long way but, using perl reasoning fIigured something like this could be done in php too.. with fewer keystrokes I'm new to php so don't laugh. Andrew Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 14, 2007 Share Posted November 14, 2007 Please post your form source. Quote Link to comment Share on other sites More sharing options...
dooh Posted November 14, 2007 Author Share Posted November 14, 2007 Here ya go, <form action = "$self" method = "post"> <input type="hidden" name="number" value="dx2201"> <input type="hidden" name="number" value="dx108"> <input type="hidden" name="number" value="sx9"> <input type="hidden" name="number" value="fx1"> <input type = "submit" value = "Submit"> </form> Andrew Quote Link to comment Share on other sites More sharing options...
gin Posted November 14, 2007 Share Posted November 14, 2007 You know, I'm not understanding what exactly you're trying to accomplish here.... Anyway, you've got 1 variable (one!) in your form. How does your form pass the information to $numbers_received & $numsA? You're getting the error because those two variables don't have any information at all. Incidentally, $value up there would hold "dx2201" not "2201" like I suspect you're hoping. All that code up there does is copy the info from one array to another in a very difficult fashion. Wouldn't it be easier to transfer your information in separated arrays? Something that would result in: $dx = array (2201, 108); $sx = array (9); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 14, 2007 Share Posted November 14, 2007 In order to pass multiple values using the same name, you need to make that name an array: <form action = "$self" method = "post"> <input type="hidden" name="number[]" value="dx2201"> <input type="hidden" name="number[]" value="dx108"> <input type="hidden" name="number[]" value="sx9"> <input type="hidden" name="number[]" value="fx1"> <input type = "submit" value = "Submit"> </form> To reference the returned values, use "$_POST['number'][0]" through "$_POST['number][3]". Ken Quote Link to comment Share on other sites More sharing options...
dooh Posted November 14, 2007 Author Share Posted November 14, 2007 Thank you kenrbnsn, Here is your answer back... $number1_received = $_POST['number'][0]; $number2_received = $_POST['number'][1]; $number3_received = $_POST['number'][2]; echo $number1_received; echo "\n"; echo $number2_received; echo "\n"; echo $number3_received; echo "\n"; but...is this what you meant? Andrew 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.