Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Location
    NYC
    Posts
    245

    Unhappy [PHP] Passing array as string from one file to the next - please help.

    Ok, I am really stuck on this and been searching on here as well as google for the last 2 hours without any luck.
    Here is the situation:

    I want to pass a multi selectable checkbox as an array to one file called index.php, so on my form page.. I have a for loop that repeats this process 16 times. The form is processed using GET method.
    PHP Code:
    echo "<input name=\"song[]\" type=\"checkbox\" value=\"".$counter."\">"
    Now, the index.php holds the variable so I retrieve it using:
    PHP Code:
    foreach($_GET['song'] as $value) { 
    echo 
    "Checked: $value\n"

    Cool, this will print out each value... now I want to pass this entire array into a second page in this manner, on the same page:
    PHP Code:
    echo "<a href=\"2nd_page.php?song=$song\">link</a> 
    I want the $song to carry out the entire array which was passed into index.php to 2nd_page.php.... how can I do that? I dont really want to print out the $value really, that was to see if it works.

    I've tried doing this on index.php
    $song = $_GET['song'];
    and then I did echo to see what shows, it simply displays "Array" nothing else. How can I do this?

    Thanks in advanced.
    -DPNY
    ---|| Avurt Inc. - ||---
    www.avurt.com
    Banners, Prints, Graphics, Web sites & Much more

  2. #2
    Join Date
    Feb 2006
    Location
    Kusadasi, Turkey
    Posts
    3,273
    It is NOT secure, but anyway I'll say how:

    serialize
    Fraud Record - Stop Fraud Clients, Report Abusive Customers.
    █ Combine your efforts to fight misbehaving clients.

    HarzemDesign - Highest quality, well designed and carefully coded hosting designs. Not cheap though.
    █ Large and awesome portfolio, just visit and see!

  3. #3
    Join Date
    Nov 2004
    Posts
    258
    You can store it in a session:

    PHP Code:
    session_start();
    $_SESSION['songs'] = $_POST['songs'];

    //Then whenever you get to the page you want to use it at assign it to a variable
    $songs $_SESSION['songs'];

    foreach(
    $songs AS $key => $value)
    {

    //do whatever


  4. #4
    Join Date
    Jul 2003
    Location
    NYC
    Posts
    245
    store into session seem's like a great idea. I am also passing down other information such as id and some other field. I can store them on session. What if the user came back and submited the form again? Is there a way to destroy the session once I do the loop and get what I wanted?
    ---|| Avurt Inc. - ||---
    www.avurt.com
    Banners, Prints, Graphics, Web sites & Much more

  5. #5
    Join Date
    Jul 2003
    Location
    NYC
    Posts
    245
    Thank you guys.. I got it working through session then I am simply destroying the session. Really appriciate all the help.
    ---|| Avurt Inc. - ||---
    www.avurt.com
    Banners, Prints, Graphics, Web sites & Much more

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •