Professional Web Applications Themes

passing variables between pages - PHP Development

Hi, I want to pass a variable between three pages. I tried to get a username from the first page through a form. Use that username in a select statement in the second page to query a table.Everything is fine up to that point. now I want to pass the same username to the third page where I have to use it to select a table name by that username and it doesn't work. I tried $_POST['username'] and the value is not passed to the third page. Is there a way of doing this? Please help. Thank You. Rashini...

  1. #1

    Default Passing variables between pages


    Hi,

    I want to pass a variable between three pages. I tried to get a username from the first page through a form. Use that username in a select statement in the second page to query a table.Everything is fine up to that point. now I want to pass the same username to the third page where I have to use it to select a table name by that username and it doesn't work. I tried $_POST['username'] and the value is not passed to the third page. Is there a way of doing this?
    Please help.

    Thank You.

    Rashini



    Rashini Guest

  2. #2

    Default Re: [PHP] Passing variables between pages

    Rashini Jayasinghe wrote: 

    Please wrap your emails to the list.

    Are you using a form to go from page two to page three? If so...

    <input type='hidden' name='username' value='<?php echo (
    $_POST['username'] ); ?>'>

    If not, save it in a session variable (I would actually use this method
    even if I did have a form on the second page).

    --
    By-Tor.com
    It's all about the Rush
    http://www.by-tor.com
    John Guest

  3. #3

    Default Re: [PHP] Passing variables between pages

    Hi,

    You need to use sessions. Please refer session handling functions in the
    manual. Having said that it's a bad idea to put username in a session.
    You need to have some kind of association between session ids and
    username's in app. The most common way this is done is with a two column
    table.

    all the best



    Rashini Jayasinghe wrote:
     


    --
    Raditha Dissanayake.
    ------------------------------------------------------------------------
    http://www.radinks.com/sftp/ | http://www.raditha/megaupload/
    Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
    Graphical User Inteface. Just 150 KB | with progress bar.
    Raditha Guest

  4. #4

    Default Passing variables between pages

    Hi,

    Simple one for anyone who wants to help out a novice. How do you pass a
    variable from one page to another?

    Urgent help would be appreciated.

    With thanks

    Kevin
    Kb Guest

  5. #5

    Default Re: Passing variables between pages

    Like John said:

    You can use:

    In the second page:
    $user = $_POST['username']; // sent by the first page
    ....
    echo "<form ...>
    <input type='hidden' name='username' value='$user'>
    ....
    </form>";

    So, when you submit the form, in the third page you will be able to get the
    username.
    $user = $_POST['username'];

    Yo can do this in N number of pages. If you always pass and obtain the
    variable via POST or GET no matter how much pages yo use. In the 20th page
    you'll get the variable.



    "Rashini Jayasinghe" <com.lk> escribió en el mensaje
    news:007c01c39206$65ce8c00$lk...

    Hi,

    I want to pass a variable between three pages. I tried to get a username
    from the first page through a form. Use that username in a select statement
    in the second page to query a table.Everything is fine up to that point. now
    I want to pass the same username to the third page where I have to use it to
    select a table name by that username and it doesn't work. I tried
    $_POST['username'] and the value is not passed to the third page. Is there a
    way of doing this?
    Please help.

    Thank You.

    Rashini
    Gabriel Guest

  6. #6

    Default passing variables between pages

    i read a tutorial the other day on passing variables between php pages
    using a html form and setting the action to the php page to p, can
    anybody see anything wrong with the code below? the problem is, that the
    page always loads the html form, and i cant work out why this is so, even
    after i select a catagory from the drop down list and press search. any1
    have any idea's? TIA.

    the code:

    if (empty($catagory)) { ?>
    <div align=center>
    <form action="<?php $PHP_SELF ?>" method="GET"> <table>
    <tr> <td>
    <INPUT name=search>
    </td> <td>
    <SELECT NAME=catagory SIZE=1>
    <OPTION any>Search All Catagories
    <OPTION floral>Floral Creations
    <OPTION lighting>Decorative Lighting
    <OPTION kitchenware>Kitchenware & Crockery <OPTION
    furniture>Fancy Goods & Furniture
    </SELECT>
    </td> <td>
    <INPUT TYPE=submit VALUE="Search">
    </td>
    </form>
    </div>
    <?php exit; }
    echo ("the catagory variable was set");
    Matthew Guest

  7. #7

    Default Re: passing variables between pages

    just thought i would add, that i cant remember the url of the tutorial,
    and the notes i took didn't include that part for some unknown reason
    Matthew Guest

  8. #8

    Default Re: passing variables between pages

    Matthew Robinson <com> schrieb:
     

    Set your error_reporting to E_ALL, so that PHP will inform you of any
    errors. Then have a look at the resulting source code of the HTML page
    and you should find your error pretty fast. You use $PHP_SELF as a
    function, but what you really want is the value of this variable.
    Additionally I'd suggest that you use $_SERVER['PHP_SELF']. $_PHP_SELF
    will not exist if register_globals is off (which is default since PHP
    4.2.0). So your code should be:

    <form action="<?php echo($SERVER['PHP_SELF'] ?>" method="GET"> <table>
     

    You forgot to close the table row and the table.

    00:53AM in Germany. I'm going to bed now. :-)

    Regards,
    Matthias
    Matthias Guest

  9. #9

    Default Re: passing variables between pages

    just thought of checking the url - thats right, so the problem must be in
    my if statement:

    end of url:
    search.php?search=&catagory=Search+All+Catagories

    if statement:

    if (empty($catagory)) {

    Matthew Guest

  10. #10

    Default Re: passing variables between pages

    Matthew Robinson wrote: 

    Read this, _all_ of this

    http://www.php.net/manual/en/language.variables.external.php


    and follow a few of the links there, too




    a (the usual?) way to do what you want is

    if (empty($_GET['catagory'])) {


    but do not bypass reading the manual :)
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--
    Pedro Guest

  11. #11

    Default Re: passing variables between pages

    Matthew Robinson <com> schrieb:
     

    if (isset($_GET['catagory'])) {

    And you might want to change "catagory" to "category". :-)

    Regards,
    Matthias
    Matthias Guest

  12. #12

    Default Re: passing variables between pages

    thanks again pedro - i am gonna read the manual now (the link you gave me)
    Matthew Guest

Similar Threads

  1. Passing ASP Variables
    By Darren Woodbrey in forum ASP Database
    Replies: 2
    Last Post: April 19th, 04:49 AM
  2. Passing Variables from swf to swf
    By vin-E in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: January 19th, 09:36 PM
  3. Replies: 3
    Last Post: November 14th, 08:16 PM
  4. variables, passing again to another.
    By Louie Miranda in forum PHP Development
    Replies: 0
    Last Post: September 25th, 07:46 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139