problem with learning PHP

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

    problem with learning PHP

    hello,

    I'm trying to learn the basics of PHP, but when I try to
    run a little simple script I received a error on my screen:

    Notice: Undefined variable: verzenden in c:\program files\apache
    group\apache\ht docs\test\formu lier1.php on line 7


    this is the source:

    <form name="formulier 1" action="formuli er1.php" method="get">
    Voer alstublieft uw voornaam in: <input type=text
    name=voornaam>< br><br>
    Voer alstublieft uw achternaam in: <input type=text
    name=achternaam ><br><br>
    <input type=submit name=verzenden>
    </form>
    <?php
    if($verzenden){
    echo "<b>Harteli jk welkom, $voornaam $achternaam.</b>";
    }
    ?>

    is my installation wrong of PHP ?

    did I forget some source ?

    thanks,

    Jonay
  • Erwin Moller

    #2
    Re: problem with learning PHP

    Jonay Herrera wrote:
    [color=blue]
    > hello,
    >
    > I'm trying to learn the basics of PHP, but when I try to
    > run a little simple script I received a error on my screen:
    >
    > Notice: Undefined variable: verzenden in c:\program files\apache
    > group\apache\ht docs\test\formu lier1.php on line 7
    >
    >
    > this is the source:
    >
    > <form name="formulier 1" action="formuli er1.php" method="get">
    > Voer alstublieft uw voornaam in: <input type=text
    > name=voornaam>< br><br>
    > Voer alstublieft uw achternaam in: <input type=text
    > name=achternaam ><br><br>
    > <input type=submit name=verzenden>[/color]

    Better would be:
    <input type=submit value="verzende n">

    and check in the following PHP for the existance of some variables.
    [color=blue]
    > </form>
    > <?php
    > if($verzenden){[/color]

    Better would be to check IF a certain variable is send to this page.
    Use isset() for this.
    So:

    if (isset($_GET["voornaam"])
    [color=blue]
    > echo "<b>Harteli jk welkom, $voornaam $achternaam.</b>";
    > }
    > ?>
    >
    > is my installation wrong of PHP ?
    >
    > did I forget some source ?
    >
    > thanks,
    >
    > Jonay[/color]


    But more important is this: You expect PHP to create the variables you send
    with your form to be automatically created, eg: you expect the variable
    $voornaam to be created JUST because you send it.
    This used to be true for older versions of PHP, but (luckily) they changed
    the default behaviour of PHP.
    This is done in the php.ini under the name of: register_global s

    here is a piece out of php.ini:

    ; You should do your best to write your scripts so that they do not require
    ; register_global s to be on; Using form variables as globals can easily
    lead
    ; to possible security problems, if the code is not very well thought of.
    register_global s = Off

    So, I guess you have register_global s set to off too, as it should be.

    Just use $_GET["varnameher e"] and $_POST["varnameher e"] to retrieve the
    values.

    Regards,
    Erwin

    Comment

    • Damir Mehmedovic

      #3
      Re: problem with learning PHP


      "Jonay Herrera" <jonay.herrera@ pandora.be> wrote in message
      news:41934070.0 401210051.497d8 d41@posting.goo gle.com...[color=blue]
      > hello,
      >
      > I'm trying to learn the basics of PHP, but when I try to
      > run a little simple script I received a error on my screen:
      >
      > Notice: Undefined variable: verzenden in c:\program files\apache
      > group\apache\ht docs\test\formu lier1.php on line 7
      >
      >
      > this is the source:
      >
      > <form name="formulier 1" action="formuli er1.php" method="get">
      > Voer alstublieft uw voornaam in: <input type=text
      > name=voornaam>< br><br>
      > Voer alstublieft uw achternaam in: <input type=text
      > name=achternaam ><br><br>
      > <input type=submit name=verzenden>
      > </form>
      > <?php
      > if($verzenden){
      > echo "<b>Harteli jk welkom, $voornaam $achternaam.</b>";
      > }
      > ?>
      >
      > is my installation wrong of PHP ?
      >
      > did I forget some source ?
      >
      > thanks,
      >
      > Jonay[/color]


      Hi,

      you can try it also with method="post" or just send verzenden as hidden
      field (it must be between <form> and </form> tags):
      <input type=hidden name=verzenden value=1>

      It's a small workaround, but it should work

      Lot of fun learning PHP.

      Regards,
      Damir


      Comment

      • Phil Roberts

        #4
        Re: problem with learning PHP

        With total disregard for any kind of safety measures "Damir
        Mehmedovic" <srebrenik_nosp am@gmx.net> leapt forth and uttered:
        [color=blue]
        > It's a small workaround
        >[/color]

        Completly wrong though.

        --
        There is no signature.....

        Comment

        • Chung Leong

          #5
          Re: problem with learning PHP

          Go into php.ini and turn off E_NOTICE.

          Uzytkownik "Jonay Herrera" <jonay.herrera@ pandora.be> napisal w wiadomosci
          news:41934070.0 401210051.497d8 d41@posting.goo gle.com...[color=blue]
          > hello,
          >
          > I'm trying to learn the basics of PHP, but when I try to
          > run a little simple script I received a error on my screen:
          >
          > Notice: Undefined variable: verzenden in c:\program files\apache
          > group\apache\ht docs\test\formu lier1.php on line 7
          >
          >
          > this is the source:
          >
          > <form name="formulier 1" action="formuli er1.php" method="get">
          > Voer alstublieft uw voornaam in: <input type=text
          > name=voornaam>< br><br>
          > Voer alstublieft uw achternaam in: <input type=text
          > name=achternaam ><br><br>
          > <input type=submit name=verzenden>
          > </form>
          > <?php
          > if($verzenden){
          > echo "<b>Harteli jk welkom, $voornaam $achternaam.</b>";
          > }
          > ?>
          >
          > is my installation wrong of PHP ?
          >
          > did I forget some source ?
          >
          > thanks,
          >
          > Jonay[/color]


          Comment

          Working...