I have been all over stack overflow and read the various answers to similar questions but I'm still experiencing a problem so I'm definitely missing something. My problem is simple:
I'm trying to pass an array from one page to another using POST. I'm not getting the response I want as demonstrated below. Any ideas?
Here is my form code:
$my_array = array("a", "b", "c", "d");
echo "<form action='post_to_this_page.php' method='post'>";
echo "<input type='hidden' name='book_ids[]' id='hiddenField' value=" $my_array " />";
echo "<input type='submit' name='formSubmit' value='Submit' />";
echo "</form>;
Here is "post_to_this_page.php:
$bookids = $_POST['book_ids'];
foreach($bookids as $thebookid)
{
echo "Book Id : " . $thebookid . "<br />";
}
This is what prints out:
Book Id : Array
Obviously I'm trying to get a response like:
Book Id : a
Book Id : b
Book Id : c
Book Id : d
I'm sure I'm doing something fundamentally wrong but I can't figure out what it is.
Thanks in advance for looking at my problem. Any insight is greatly appreciated!
book_idarray. If you want more positions, you have to create more field inputs withbook_id[]as name. And finally, you are echoing an array which is not correct because you will get a nice string sayingArrayand for that reason prints outArray.