Professional Web Applications Themes

Getting undefinded error - PHP Development

Good day, I'm currently learning how to programming in PHP and using WROX Beginning PHP4 book. Now working with some of the examples from the book and I'm getting an undefined error when I process the script which gets a simple text input from a form. I've tripled verified the code from the book and it is correct. I'm not sure what is going on and nned some help. I'm using the latest version of PHP on a Windows 2000 server. If you need any further information, I will provide it. Thanks in advance....

  1. #1

    Default Getting undefinded error

    Good day,

    I'm currently learning how to programming in PHP and using WROX Beginning
    PHP4 book. Now working with some of the examples from the book and I'm
    getting an undefined error when I process the script which gets a simple
    text input from a form. I've tripled verified the code from the book and it
    is correct. I'm not sure what is going on and nned some help. I'm using
    the latest version of PHP on a Windows 2000 server.

    If you need any further information, I will provide it. Thanks in advance.


    ChevyDriver Guest

  2. #2

    Default Re: Getting undefinded error

    I noticed that Message-ID: <Rq3ze.625$cgocable.net> from
    ChevyDriver contained the following:
     

    Variables obtained from a form are only defined when the form is
    submitted.

    This will give a notice before the form is submitted:

    print $_POST['textbox_name'];

    To avoid the notice do:

    if(isset($_POST['textbox_name'])){
    print $_POST['textbox_name'];
    }
     

    Ummm, a look at the code would be helpful...



    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

  3. #3

    Default Re: Getting undefinded error

    Here is the exaple from the book that I'm using.

    The first page is a simple html page with a form and the coding they use is
    this:

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>

    <form method="get" action="text.php">
    Who is your favourite author?
    <input name="Author" type="text">
    <br>
    <br>
    <input type="Submit">
    </form>

    </body>
    </html>

    The php code they use for the php file is this:

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>

    Your favourite author is:
    <?php
    echo $Author;
    ?>

    </body>
    </html>

    Thanks for the help.


    "Geoff Berrow" <co.uk> wrote in message
    news:com... 
    >
    > Variables obtained from a form are only defined when the form is
    > submitted.
    >
    > This will give a notice before the form is submitted:
    >
    > print $_POST['textbox_name'];
    >
    > To avoid the notice do:
    >
    > if(isset($_POST['textbox_name'])){
    > print $_POST['textbox_name'];
    > }

    >
    > Ummm, a look at the code would be helpful...
    >
    >
    >
    > --
    > Geoff Berrow 0110001001101100010000000110
    > 001101101011011001000110111101100111001011
    > 100110001101101111001011100111010101101011[/ref]


    ChevyDriver Guest

  4. #4

    Default Re: Getting undefinded error

    I noticed that Message-ID: <UyHze.9889$cgocable.net> from
    ChevyDriver contained the following:
     

    I'm afraid your book is out of date. It assumes that register globals
    is set to 'on' and the default these days is 'off'. What this means is
    that all variables that you feed into a form are automatically
    registered, that is the names of form elements will appear as variables
    in the script. The method of the form element denotes the way the
    variable is passed. 'get' means it is passed in the URL, 'post' means
    they are sent invisibly.

    The recommended way of dealing with this now is to assume register
    globals is off. The values are still available in the GET and POST
    arrays as I showed before but obviously I should have used GET rather
    than POST.

    The second problem is in the notice. Earlier versions of PHP had error
    reporting set to a level where notices were suppressed. A notice is
    PHPs way of saying 'I understand this but it's not strictly correct'
    Mostly it will be ok but again it is good practice to code so as not to
    get notices.
    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

Similar Threads

  1. Replies: 0
    Last Post: March 29th, 09:49 PM
  2. Replies: 0
    Last Post: November 10th, 05:24 PM
  3. Object Undefinded index
    By Steve in forum PHP Development
    Replies: 4
    Last Post: October 30th, 09:40 AM
  4. Replies: 1
    Last Post: August 7th, 07:13 PM

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