SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best Practices? Passing variables from php page to php page.

    Hi everyone! First post. Absolute beginner. Have most Sitepoint books.
    I'm still not clear on what the best practices is on transferring data from page to page to page. I have a simple form with Name Title1 Title2..., Phone 1, Phone 2,... Email, etc., about 12 variables in all. As the user progresses from page to page, I find myself sending data by using:

    header('Location: bctemplstandardproof.php?Name='.$Name.'?Title1='.$Title1.'?Title2='.$Title2.'?Title3='.$Title3.'?Title4='.$Title4.'?Email='.$Email.'?Phone1='.$Phone1.'?Phone2='.$Phone2.'?Phone3='.$Phone3.'?Phone4='.$Phone4.'?MailStop='.$Mailstop.'?po='.$po); or
    <a href="bctemplstandard.php?po=<?php echo $po;?>"><img src="images/MoffittStandardExampleTitleBC.png"</a>

    I'm not sure this is best practice. COOKIES and SESSIONS may be too advanced for me, and may be overkill. Any thoughts? Thanks in advance...

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,823
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A session would probably be the simplest way - far simpler than what you are currently using.

    You simply need a session_start at the top of the PHP and then assign the fields into the $SESSION array and read them back from there in the following page instead of from the $_GET array.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with felgall.

    But if you want to use a query string like you have, a ? denotes the beginning of the query string in the url and subsequent name/value pairs are separated by an & and not a ?

  4. #4
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much! I really messed that up! & not ?.

    I'll be switching to sessions, thanks!


Tags for this Thread

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
  •