Help with passing variables to another php script

Discussion in 'PHP' started by jber, Jul 19, 2007.

  1. #1
    Hello!

    I need some help about passing variables to another php script.
    In the script A i receive the variable called menu and i show it to confirm its value
    $menu = $_POST["menu"];

    echo 'You selected ' .$menu. '</br>';

    My problem is that in this script A i have a form the users fill to continue navigating through the site, and they have to select another options , and they will be directed to another script, script B.

    Something like this ...

    echo '<form action="scriptB.php?nombre_tabla=$menu" method="post">';

    i know it doesn´t work, but i want to pass the variable menu to script B so i can use it in another functions

    ¿How can i do it?
    ¿How can i recover the variable´s value in script B?

    Any help will be well received

    Jber
     
    jber, Jul 19, 2007 IP
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can probably retreive it through $_GET as it will be passed in the url.

    A better method, however, would be to put a hidden form element in your form containing that value.

    <input type="hidden" name="nombre_tabla" value="$menu">
     
    ecentricNick, Jul 19, 2007 IP
  3. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Might want to look into using a session to use data across all the pages in your application.
     
    mrmonster, Jul 19, 2007 IP
  4. jber

    jber Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you for your help
    I´ll try both solutions

    Thanks again
    Jber
     
    jber, Jul 19, 2007 IP
  5. jber

    jber Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The hidden solution does not work, because if i put :

    echo '<input type="hidden" name="nombre_tabla" value="$menu" >';

    as you´ve told me , i receive, in script B

    Seleccionaste el campo identificador de la tabla $menu and not the value of the variable

    ¿Can you help me please?

    Jber
     
    jber, Jul 19, 2007 IP
  6. jber

    jber Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It works now

    the solution was

    echo '<input type="hidden" name="nombre_tabla" value='.$menu.'>';
     
    jber, Jul 19, 2007 IP
  7. alper120

    alper120 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thank you all forums
     
    alper120, Jul 19, 2007 IP