Forms, post and register_globals

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dariusz

    Forms, post and register_globals

    I have a simple form which I want to try out (before rewriting to do
    something useful)... and am having problems getting the variable to output.
    From what I read I have coded it to get around the "register_globa ls"
    being off (both on my localhost and my ISP)... but I cannot get the
    variable output, below is my HTML and PHP.

    Basically, the HTML file contains a form with a select box which is
    supposed to pass the variable to the PHP script so it can print the result
    of the variable selected.

    After much searching online and head scratching, I can't find what I've
    done wrong. Can anyone help?

    Dariusz


    ++HTML++

    <HTML><HEAD><TI TLE>Redirector test</TITLE></HEAD>
    <BODY>

    <FORM method="POST" action="redirec tor.php">
    <select name="$_POST['album']">
    <option value="a01-t01" SELECTED>Album 01, Track 01</option>
    <option value="a01-t02">Album 01, Track 02</option>
    </select>
    <input type="submit" value="Submit">
    </FORM>

    </BODY>
    </HTML>


    ++PHP++

    <?

    echo ('The results is: $album');

    ?>
  • Justin Koivisto

    #2
    Re: Forms, post and register_global s

    Dariusz wrote:
    [color=blue]
    > I have a simple form which I want to try out (before rewriting to do
    > something useful)... and am having problems getting the variable to output.
    > From what I read I have coded it to get around the "register_globa ls"
    > being off (both on my localhost and my ISP)... but I cannot get the
    > variable output, below is my HTML and PHP.[/color]

    You've got them backwards...
    [color=blue]
    > ++HTML++
    > <select name="$_POST['album']">[/color]

    <select name="album">
    [color=blue]
    > ++PHP++
    > echo ('The results is: $album');[/color]

    echo 'The results is: ',$_POST['album'];

    --
    Justin Koivisto - spam@koivi.com
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Comment

    • Matthias Esken

      #3
      Re: Forms, post and register_global s

      ng@lycaus.plusY OURSHIT.com (Dariusz) schrieb:
      [color=blue]
      > ++HTML++
      >
      > <FORM method="POST" action="redirec tor.php">
      > <select name="$_POST['album']">
      > <option value="a01-t01" SELECTED>Album 01, Track 01</option>
      > <option value="a01-t02">Album 01, Track 02</option>
      > </select>
      > <input type="submit" value="Submit">
      > </FORM>[/color]

      <form method='post' action='redirec tor.php' name='myform'>
      <select name='album'>
      <option value='a01-t01' selected='selec ted'>
      Album 01, Track 01</option>
      <option value='a01-t02'>
      Album 01, Track 02</option>
      </select>
      <input type='submit' name='submit' value='Submit'>
      </form>
      [color=blue]
      > ++PHP++
      >
      > <?
      > echo ('The results is: $album');
      > ?>[/color]

      <?
      echo ("The result is {$_POST['album']}");
      ?>

      or better

      <?php
      if (isset($_POST['album'])) {
      echo ('The result is: ' . $_POST['album']);
      }
      ?>

      Compare your code and my code and try to find out what you've done
      wrong. If you really can't figure it out and need more explanations feel
      free to ask again.

      Regards,
      Matthias

      Comment

      • Dariusz

        #4
        Re: Forms, post and register_global s

        In article <jvswb.1193$Uz. 37639@news7.onv oy.net>, Justin Koivisto <spam@koivi.com > wrote:[color=blue]
        >You've got them backwards...
        >[color=green]
        >> ++HTML++
        >> <select name="$_POST['album']">[/color]
        >
        ><select name="album">
        >[color=green]
        >> ++PHP++
        >> echo ('The results is: $album');[/color]
        >
        >echo 'The results is: ',$_POST['album'];
        >[/color]

        Thanks for that... I thought it must be something simple as there was not
        much code there to get wrong !!

        Dariusz

        Comment

        • Dariusz

          #5
          Re: Forms, post and register_global s

          In article <bpto91.1fg.1@u senet.esken.de> , Matthias Esken <netzkontroll e-nospam@usenetve rwaltung.org> wrote:[color=blue]
          >ng@lycaus.plus YOURSHIT.com (Dariusz) schrieb:[/color]

          Okay the HTML you you corrected I redid...
          [color=blue][color=green]
          >> ++PHP++[/color]
          ><?
          >echo ("The result is {$_POST['album']}");
          >?>[/color]

          Now with the correct PHP code, the thing works. Thanks for that :-).
          [color=blue]
          >or better
          >
          ><?php
          >if (isset($_POST['album'])) {
          > echo ('The result is: ' . $_POST['album']);
          > }
          >?>
          >
          >Compare your code and my code and try to find out what you've done
          >wrong. If you really can't figure it out and need more explanations feel
          >free to ask again.[/color]

          Well, as you bring it up, what is the difference between the first PHP code
          and the second? Which is better to use? Why? etc...

          Dariusz

          Comment

          • Matthias Esken

            #6
            Re: Forms, post and register_global s

            ng@lycaus.plusY OURSHIT.com (Dariusz) schrieb:
            [color=blue]
            > In article <bpto91.1fg.1@u senet.esken.de> , Matthias Esken <netzkontroll e-nospam@usenetve rwaltung.org> wrote:[color=green]
            >> ng@lycaus.plusY OURSHIT.com (Dariusz) schrieb:[/color]
            >[color=green][color=darkred]
            >>> ++PHP++[/color]
            >> <?
            >> echo ("The result is {$_POST['album']}");
            >> ?>
            >>
            >> or better
            >>
            >> <?php
            >> if (isset($_POST['album'])) {
            >> echo ('The result is: ' . $_POST['album']);
            >> }
            >> ?>
            >>
            >> Compare your code and my code and try to find out what you've done
            >> wrong. If you really can't figure it out and need more explanations feel
            >> free to ask again.[/color]
            >
            > Well, as you bring it up, what is the difference between the first PHP code
            > and the second? Which is better to use? Why? etc...[/color]

            If you call the php script without posting a value for 'album' it will
            throw a warning in the first case. Then it will assume, that
            $_POST['album'] might be an empty string (or maybe a number with the
            value 0), create the variable $_POST['album'] and output the data. You
            rely on the interpreters guess, what you really wanted to do.

            In the second case the script checks if it received a value and will not
            output anything if there was no value.

            Regards,
            Matthias

            Comment

            Working...