SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing variables using header location?

    Hello

    I have an online form and I want to get the values of the form posted through to my next page. Now I have to use header to submit the form to the next page rather than through the form element, as I want to get the number value that I post in my first box num (which I can) But I also want the values I post for Gallery Name and Credit to be avaliable to me on the next page? Which I can't How can I do this?

    Here's the basics of my page(S)

    First Page

    PHP Code:
    <?
    if (isset($_POST['Submit'])) 

        
    header("Location: upload.php?num=".$_POST['num'].""); 
    }
    ?>

    <form id="webform" action="" method="post"  name="webform">

    <!-- How Many pictures would you like to upload to the gallery --> 
        <label>How many pictures:
        <span class="small">Please type in how many pics you would like to upload</span>
        </label>
        <input name="num" class="big" type="text" id="num" style="width: 300px" value="" />
     <div class="spacer"></div> 

    <!-- What is the Gallery Name --> 
        <label>Gallery Name:
        <span class="small">Please enter a gallery title</span>
        </label>
        <input name="the_title" class="big" type="text" id="the_title" style="width: 300px" value="" />
        <div class="spacer"></div> 
        
    <!-- Who took the pictures --> 
        <label>Credit:
        <span class="small">Who took these pictures</span>
        </label>
        <input name="credit" class="big" type="text" id="credit" style="width: 300px" value="" />
        <div class="spacer"></div> 

    </form>
    Second Page - upload.php accesses when I hit submit

    PHP Code:
    Pictures to Upload : <?php echo $_GET['num']; ?> <br />
    Gallery Name : ?How can I get this value posted on this page from the first page? <br />
    Credit : ?How can I get this value posted on this page from the first page? <br />
    Can anyone kindly help

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $args = array(
        
    'num' => $_POST['num'],
        
    'the_title' => $_POST['the_title']
    ...
    etc...
    );

    echo 
    'upload.php?' http_build_query($args); 

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but I don't quite get what you mean? Something like?

    PHP Code:
    <? 
    if (isset($_POST['Submit'])) 


    $args = array( 
    'num' => $_POST['num'], 
    'the_title' => $_POST['the_title'
    ); 

    header("Location: upload.php?' . http_build_query($args)"); 

    ?>
    Then also how would I coutput the the_title on the next page when I hit submit?

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Variables in the querystring are retreived via $_GET:
    PHP Code:
    echo $_GET['the_title']; 

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but how about the header location?

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header("Location: upload.php?" . http_build_query($args));


Bookmarks

Posting Permissions

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