www.webdeveloper.com
Results 1 to 11 of 11

Thread: Trying to pass array variable to new page

  1. #1
    Join Date
    May 2005
    Location
    Wichita Falls, TX
    Posts
    31

    Trying to pass array variable to new page

    I'm trying to pass an array of strings to a new page. On the new page when I try to retrieve the value of the array all it does is spell out Array. What is the problem?

    The variable I'm trying to pass is $queries
    Code:
    echo"<br><br>Would you like to join this table with another?<br>
    	<form method = 'post' action = querymaker2.php>
    	<input type = radio name = rdo1 value = 1>yes
    	<input type = radio name = rdo1 value = 0>no
    	<input type = hidden name = queries value = '$queries'>
    	<input type = submit name = submit value = submit>
    	</form>";
    and I'm retrieving it like this
    Code:
    while(list($key, $value) = each($HTTP_POST_VARS)) 
    		{ 
    			echo $value;
    		}
    And trust me I've tried it several different ways. It always returns the same value of Array

  2. #2
    Join Date
    Jan 2005
    Location
    Lithia Springs, GA USA
    Posts
    886
    You got a bunch of incorrect stuff there...
    PHP Code:
    echo"<br><br>Would you like to join this table with another?<br>
        <form method = 'post' action = querymaker2.php>
        <input type = radio name = rdo1 value = 1>yes
        <input type = radio name = rdo1 value = 0>no
        <input type = hidden name = queries value = '
    $queries'>
        <input type = submit name = submit value = submit>
        </form>"

    Should be...
    PHP Code:
    echo'<br><br>Would you like to join this table with another?<br>
        <form method="post" action="querymaker2.php">
        <input type="radio" name="rdo1" value="1">yes
        <input type="radio" name="rdo1" value="0">no
        <input type="hidden" name="queries" value="' 
    $queries '">
        <input type="submit" name="submit" value="submit">
        </form>'


  3. #3
    Join Date
    May 2005
    Location
    Wichita Falls, TX
    Posts
    31
    Where do you find the protocol for this. I haven't used PHP in about 2 years and now I'm getting back to using it and a lot of small things have changed.

  4. #4
    Join Date
    May 2005
    Location
    Australia
    Posts
    134
    www.php.net welcome back

  5. #5
    Join Date
    May 2005
    Location
    Wichita Falls, TX
    Posts
    31
    Those code changes didn't change anything.

  6. #6
    Join Date
    Jul 2005
    Posts
    95
    How I might do it:

    PHP Code:
    <br><br>Would you like to join this table with another?<br>
        
    <form method="POST" action="querymaker2.php">
        <input type="radio" name="rdo1" value="1">yes
        <input type="radio" name="rdo1" value="0">no
        <input type="hidden" name="queries" value="<? echo $queries?>">
        <input type="submit" name="submit" value="submit">
    </form>
    And then receive:

    PHP Code:
    <?
        
    foreach( $_POST as $value ) {
            echo 
    $value;
        }
    ?>
    PHP Nerd
    -------------------------
    If you save a syntax error, and don't load the page, does it make an error?

  7. #7
    Join Date
    Jan 2005
    Location
    Lithia Springs, GA USA
    Posts
    886
    Quote Originally Posted by CompGeek01
    How I might do it:

    PHP Code:
    <br><br>Would you like to join this table with another?<br>
        
    <form method="POST" action="querymaker2.php">
        <input type="radio" name="rdo1" value="1">yes
        <input type="radio" name="rdo1" value="0">no
        <input type="hidden" name="queries" value="<? echo $queries?>">
        <input type="submit" name="submit" value="submit">
    </form>
    And then receive:

    PHP Code:
    <?
        
    foreach( $_POST as $value ) {
            echo 
    $value;
        }
    ?>
    That is not how he had it though. He had it in an echo statement.

    And the things I changed didn't have much to do with PHP as much as it had to do with proper HTML coding.

    Also you must be more specific than "Those code changes didn't change anything."

    I am sorry but my telepathic powers are on the blink today... sunspots I believe is the cause

  8. #8
    Join Date
    Jul 2005
    Posts
    95
    If you can't copy and paste then I can't help you. I'm sorry if thats not how he had it...because it's "How I would do it".

    Otherwise I wouldn't have put the disclaimer.
    PHP Nerd
    -------------------------
    If you save a syntax error, and don't load the page, does it make an error?

  9. #9
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    while(list($key, $value) = each($HTTP_POST_VARS))
    {
    echo $value;
    }

    The above has nothing to do with the question but is an old PHP 3 construct and should work fine unless you have $HTTP_POST_VARS disabled in php.ini.

    Now to your question which no one has answered yet.

    Replace this line in your script:
    PHP Code:
    <input type="hidden" name="queries" value="<? echo $queries?>">
    With this:
    PHP Code:
    <?php foreach($queries as $key => $value){print '<input type="hidden" name="queries['.$key.']" value="'.$value.'">'."\n";}?>
    Now after the form has been submitted $_POST['queries'] will be an array which is identical to your $queries array. Although this writes a hidden field for each key/value pair it will save any nonsense converting to and from a string.

    Obviously the whole purpose of hidden data is to maintain an identical copy of the original data and that is exactly what this method does.
    Last edited by bokeh; 07-27-2005 at 01:00 AM.

  10. #10
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,225
    Another possibility: use a sessions and save the array to a $_SESSION variable.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #11
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    564
    PHP Code:
    extract $_POST ); 
    http://www.php.net/manual/en/function.extract.php

    Answers to all your questions can be found at: PHP Manual

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles