bobbychla Posted September 7, 2011 Share Posted September 7, 2011 i created an array like this while{ $ir = 0; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['id_sub']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_topic']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['attendance']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['internal_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['external_mark']; $ir++; } echo "<input type='hidden' name='ar_std' id='ar_std' value='$stud' /> </table>" ; and it is able to print in the same page using foreach ($stud as $v1) { echo "$v1\n<br>"; foreach ($v1 as $v2) { echo "$v2\n<br>"; } } and in the next page $ar_stud[]=$_POST["ar_std"]; I'm getting an error PHP Warning: Invalid argument supplied for foreach() in save.php on line 25 PHP Stack trace: Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/ Share on other sites More sharing options...
bobbychla Posted September 7, 2011 Author Share Posted September 7, 2011 Can we pass array in $_POST method ? if yes plz give me the tips. Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/#findComment-1266572 Share on other sites More sharing options...
voip03 Posted September 7, 2011 Share Posted September 7, 2011 http://www.tanzilo.com/2008/11/09/php-pass-all-post-and-get-variables-in-array-in-function-parameter/ Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/#findComment-1266586 Share on other sites More sharing options...
btherl Posted September 7, 2011 Share Posted September 7, 2011 An array can't be passed directly like that, but you can serialize it: <?php $stud_serialized = serialize($stud); echo "<input type='hidden' name='ar_std' id='ar_std' value='$stud_serialized' /> </table>" ; // And in your receiving script $ar_stud = unserialize($_POST["ar_std"]); ?> But you are probably better off storing it in $_SESSION Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/#findComment-1266618 Share on other sites More sharing options...
xyph Posted September 7, 2011 Share Posted September 7, 2011 If you pass it using a session, be sure to have a unique token attached to that request, and pass it in a hidden field. $_SESSION['formData'][$token] = whatever array of data you want That way, someone submitting another form in a different tab that uses sessions to hold the information won't corrupt values in the original tab. This behavior will annoy a multitasking user and be very hard to debug. This is a BAD use of session though, IMO. A better way to do this would be to pass the parameters you used in your query over to the next page, and retrieve the data again. Most engines will still have the results in memory and it will be lightning fast - at LEAST as fast as retrieving the values from a flat file using sessions. This is all speculative though, as I don't know how your script works in it's entirety. Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/#findComment-1266642 Share on other sites More sharing options...
pein87 Posted September 8, 2011 Share Posted September 8, 2011 You can if your trying to do multi deletes using html. Set you checkbox input tag's name attribute to myName[] or as an example <form action="del.php" method="post"> <input type="checkbox" name="ids[]" value="1" /> <input type="checkbox" name="ids[]" value="2" /> </form> $ids = $_POST['ids']; foreach($ids as $id) { echo $id . "<br />"; } There are other methods though and you may google for a function that allows you to do that or write your own. Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/#findComment-1266674 Share on other sites More sharing options...
KevinM1 Posted September 8, 2011 Share Posted September 8, 2011 ANY group of form fields whose name is written in array notation (e.g., "textbox[]") will be handled as an array, not just checkboxes. Quote Link to comment https://forums.phpfreaks.com/topic/246658-array-passing-in-post-method-error/#findComment-1266678 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.