ISSET problem for a newby

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

    ISSET problem for a newby

    Dear NG'ers,

    I try to learn PHP and found several examples for a HTML form to add a
    record to a database. I started out with just checking the workings of a
    html form with PHP and am completely confused with the workings.

    If I use GET to send the form I can clearly see the information exists. But
    the second time the page is requested the action i expect (no show of the
    form) is not executed.
    The POST to send the form results in the same behavior.
    I changed the location of the function to write the form from the body to
    the head section and there is no difference in the behavior (as expected)

    This is the code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head><title>IS SET1 testen</title>
    <?php
    function schrijfForm() {
    print "<form action=\"isset_ test1.php\" method=\"POST\" >\n" ;
    print "Voer nieuwe tekst in... \t" ;
    print "<input type=\"text\" name=\"tekst1\" >\n " ;
    print "<input type=\"submit\" value=\"Voeg Toe!\"
    name=\"ditform\ ">\n</form>\n" ;
    }
    ?>
    </head>
    <body>
    <?php
    if ( isset( $ditform ) ) {
    print "\$ditform is gezet: \t$ditform\n" ;
    print "\$tekst1 is gezet: \t$tekst1\n" ;
    } else {
    print "HET BESTAAT NIET\n" ;
    schrijfForm() ;
    }
    ?>
    <p>wat tekst </p>
    </body>
    </html>

    I would appreciate some explanation of why this code doesn't work?

    tia

    pablo k



  • Andreas Paasch

    #2
    Re: ISSET problem for a newby

    pablo wrote:
    [color=blue]
    >
    > I would appreciate some explanation of why this code doesn't work?
    >[/color]

    This one works fine:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head><title>IS SET1 testen</title>
    <?php
    function schrijfForm() {
    print "<form action=\"test.p hp\" method=\"POST\" >\n" ;
    print "Voer nieuwe tekst in... \t" ;
    print "<input type=\"text\" name=\"tekst1\" >\n " ;
    print "<input type=\"submit\" value=\"Voeg Toe!\"
    name=\"ditform\ ">\n</form>\n" ;
    }
    ?>
    </head>
    <body>
    <?php
    $ditform = $_POST["ditform"];
    $tekst1 = $_POST["tekst1"];
    if ( isset( $ditform ) ) {
    print "\$ditform is gezet: \t$ditform\n" ;
    print "\$tekst1 is gezet: \t$tekst1\n" ;
    } else {
    print "HET BESTAAT NIET\n" ;
    schrijfForm() ;
    ?>
    <p>wat tekst</p>
    </body>
    </html>


    The reason seems to be that register_global s is off, as it should due to
    some security.
    Now, your form is posting the data, but due to register_global s being off,
    nothing is receiving the data.
    That's why $_POST is used to get the data, for consistency the posted
    variables are assigned to the original variables.

    Pay attention to the fact, that I renamed the form to run for test.php, so
    the above code _must_ be in a page named test.php - or if you stick to the
    original form, the page where the code appears _must_ then be named
    isset_test1.php else it will fail - it is self referencing (calling
    itself).
    Self reference can also be obtained using $PHP_SELF.

    HTH,

    Andreas
    --
    Peace and long life ...
    Registeret Linux user #292411

    Comment

    • pablo

      #3
      Re: ISSET problem for a newby


      "Andreas Paasch" <Andreas@Paasch .Net> wrote in message
      news:avT8c.1284 65$jf4.6965706@ news000.worldon line.dk...
      (...some deleted code)[color=blue]
      > The reason seems to be that register_global s is off, as it should due to
      > some security.
      > Now, your form is posting the data, but due to register_global s being off,
      > nothing is receiving the data.
      > That's why $_POST is used to get the data, for consistency the posted
      > variables are assigned to the original variables.
      >
      > Pay attention to the fact, that I renamed the form to run for test.php, so
      > the above code _must_ be in a page named test.php - or if you stick to the
      > original form, the page where the code appears _must_ then be named
      > isset_test1.php else it will fail - it is self referencing (calling
      > itself).
      > Self reference can also be obtained using $PHP_SELF.
      >
      > HTH,[/color]
      So happy to be on the receiving end of your HELP!
      I have been wondering and experimenting for three whole days!

      Friede und ein langes Leben, indeed.
      [color=blue]
      >
      > Andreas
      > --
      > Peace and long life ...
      > Registeret Linux user #292411[/color]


      Comment

      • Agelmar

        #4
        Re: ISSET problem for a newby

        Andreas Paasch wrote:[color=blue]
        > pablo wrote:
        >[color=green]
        >>
        >> I would appreciate some explanation of why this code doesn't work?
        >>[/color]
        >
        > This one works fine:
        > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        > <html>
        > <head><title>IS SET1 testen</title>
        > <?php
        > function schrijfForm() {
        > print "<form action=\"test.p hp\" method=\"POST\" >\n" ;
        > print "Voer nieuwe tekst in... \t" ;
        > print "<input type=\"text\" name=\"tekst1\" >\n " ;
        > print "<input type=\"submit\" value=\"Voeg Toe!\"
        > name=\"ditform\ ">\n</form>\n" ;
        > }[color=green]
        >>[/color]
        > </head>
        > <body>
        > <?php
        > $ditform = $_POST["ditform"];
        > $tekst1 = $_POST["tekst1"];
        > if ( isset( $ditform ) ) {
        > print "\$ditform is gezet: \t$ditform\n" ;
        > print "\$tekst1 is gezet: \t$tekst1\n" ;
        > } else {
        > print "HET BESTAAT NIET\n" ;
        > schrijfForm() ;[color=green]
        >>[/color]
        > <p>wat tekst</p>
        > </body>
        > </html>
        >
        >
        > The reason seems to be that register_global s is off, as it should due
        > to some security.
        > Now, your form is posting the data, but due to register_global s being
        > off, nothing is receiving the data.
        > That's why $_POST is used to get the data, for consistency the posted
        > variables are assigned to the original variables.
        >
        > Pay attention to the fact, that I renamed the form to run for
        > test.php, so the above code _must_ be in a page named test.php - or
        > if you stick to the original form, the page where the code appears
        > _must_ then be named isset_test1.php else it will fail - it is self
        > referencing (calling itself).
        > Self reference can also be obtained using $PHP_SELF.
        >
        > HTH,
        >
        > Andreas[/color]

        Actually, $PHP_SELF requires register_global s = On;
        Instead, use $_SERVER['PHP_SELF']


        Comment

        • Andreas Paasch

          #5
          Re: ISSET problem for a newby

          Agelmar wrote:
          [color=blue]
          > Andreas Paasch wrote:[color=green]
          >> pablo wrote:
          >>[color=darkred]
          >>>
          >>> I would appreciate some explanation of why this code doesn't work?
          >>>[/color]
          >>
          >> This one works fine:
          >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          >> <html>
          >> <head><title>IS SET1 testen</title>
          >> <?php
          >> function schrijfForm() {
          >> print "<form action=\"test.p hp\" method=\"POST\" >\n" ;
          >> print "Voer nieuwe tekst in... \t" ;
          >> print "<input type=\"text\" name=\"tekst1\" >\n " ;
          >> print "<input type=\"submit\" value=\"Voeg Toe!\"
          >> name=\"ditform\ ">\n</form>\n" ;
          >> }[color=darkred]
          >>>[/color]
          >> </head>
          >> <body>
          >> <?php
          >> $ditform = $_POST["ditform"];
          >> $tekst1 = $_POST["tekst1"];
          >> if ( isset( $ditform ) ) {
          >> print "\$ditform is gezet: \t$ditform\n" ;
          >> print "\$tekst1 is gezet: \t$tekst1\n" ;
          >> } else {
          >> print "HET BESTAAT NIET\n" ;
          >> schrijfForm() ;[color=darkred]
          >>>[/color]
          >> <p>wat tekst</p>
          >> </body>
          >> </html>
          >>
          >>
          >> The reason seems to be that register_global s is off, as it should due
          >> to some security.
          >> Now, your form is posting the data, but due to register_global s being
          >> off, nothing is receiving the data.
          >> That's why $_POST is used to get the data, for consistency the posted
          >> variables are assigned to the original variables.
          >>
          >> Pay attention to the fact, that I renamed the form to run for
          >> test.php, so the above code _must_ be in a page named test.php - or
          >> if you stick to the original form, the page where the code appears
          >> _must_ then be named isset_test1.php else it will fail - it is self
          >> referencing (calling itself).
          >> Self reference can also be obtained using $PHP_SELF.
          >>
          >> HTH,
          >>
          >> Andreas[/color]
          >
          > Actually, $PHP_SELF requires register_global s = On;
          > Instead, use $_SERVER['PHP_SELF'][/color]

          You are correct, I just pulled it out of memory ... haven't been on PHP for
          a while, fighting with setting up a mailserver to my needs ...

          --
          Peace and long life ...
          Registeret Linux user #292411

          Comment

          • pablo

            #6
            Re: ISSET problem for a newby

            Thanks a lot to all respondents!

            pablo k


            Comment

            Working...