jbond Posted April 9, 2008 Share Posted April 9, 2008 Hi all, I am trying to pass an array of elements (gathered from a form) from one page to another page where they will be inserted into an mysql db. I haven't got the faintest clue on how to do this. When submitting the form, the second page is called but no data is passed. I read a lot of stuff about serialization etc, but how this works, I simply don't understand. Has anyone had such a situation where data from an array needs to go from one page to another and how can this be done? Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2008 Share Posted April 9, 2008 It is not clear if you are talking about your form sending data to the form processing page or your form processing page sending data to another page. If the problem is between your form and your form processing page, you would need to post your code for your form and your form processing page. If your question is about passing data from your form processing page to another page, either use a session or put all the code related to the form data on your form processing page (that is why the target page of a form is called the form processing page.) Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513084 Share on other sites More sharing options...
jbond Posted April 9, 2008 Author Share Posted April 9, 2008 thank you for your quick reply. Will try to post code today (am presently following evening classes photoshop and not at my computer). Cheers Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513123 Share on other sites More sharing options...
writer Posted April 9, 2008 Share Posted April 9, 2008 I am trying to pass an array of elements (gathered from a form) from one page to another page where they will be inserted into an mysql db. Read up on $_GET and $_POST. They more-or-less do the same thing, and are probably what you're looking for. Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513170 Share on other sites More sharing options...
kenrbnsn Posted April 9, 2008 Share Posted April 9, 2008 I would use sessions. In the first script: <?php session_start(); $_SESSION['post'] = $_POST; ?> in the second script: <?php session_start(); ?> and then reference $_SESSION['post']['form_field_name'] instead of $_POST['form_field_name'] Ken Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513173 Share on other sites More sharing options...
duclet Posted April 9, 2008 Share Posted April 9, 2008 I think for this particular case, you are better off using $_GET or $_POST. Using $_SESSION has the drawn back of unexpected behavior if there is a page refresh and data lingering while it shouldn't. You should be able to do something like the following: $myarray = array(...something data...); $myarrayasstring = htmlentities(serialize($myarray)); <a href="somelink.php?arraydata=<?= $myarrayasstring; ?>">Send</a> ... $data = unserialize(htmlentity_decode($_GET['arraydata'])); I might have misspelled some of the function names but you get the idea. Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513196 Share on other sites More sharing options...
jbond Posted April 10, 2008 Author Share Posted April 10, 2008 thank you all for your input. I had following in mind (a) routine which holds the form where the user can input his data. Multicon being the array that holds the data. on its turn, it calls another program add_multicon.php // multicon.html <body> <form method="post" name="form1" action="add_multicon.php"> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="submit" /> </form> </body> (b) add_multicon.php <?php // analyse what came in from the form // query still needs to be activated for($i=0;$i<count($multicon);$i++){ echo $multicon[$i]; if($multicon[$i] == "") break; // mysql_query("INSERT INTO table..."); } ?> problem that I now have is that the called routine (add_multicon.php) doesn't reckognize the array. probably I am missing something somewhere, but can't find what is causing the problem... Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513658 Share on other sites More sharing options...
jbond Posted April 10, 2008 Author Share Posted April 10, 2008 Figured it out, using the $_POST command as suggested by a couple of forum members, for which thank you very much Below is the code that works, should anyone, facing the same problem, be interested in <?php // analyse what came in from the form // query still needs to be activated if($_POST['submit']) { $vars=count($_POST['multicon']); for($i=0;$i<$vars;$i++){ echo ($_POST['multicon'][$i]); echo "\r"; if($_POST['multicon'][$i] == "") break; // mysql_query("INSERT INTO table..."); } } ?> <form method="post"> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="text" name="multicon[]" /> <input type="submit" value="submit" name="submit"/> </form> Thank you to everyone for their input.. Link to comment https://forums.phpfreaks.com/topic/100344-passing-an-array-from-one-page-to-another-page/#findComment-513690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.