Help - Search - Member List - Calendar
Full Version: Getting undefinded error
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
ChevyDriver
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.

Geoff Berrow
I noticed that Message-ID: <Rq3ze.625$[Email Removed]> from
ChevyDriver contained the following:

QUOTE
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.

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'];
}

QUOTE
If you need any further information, I will provide it.

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



--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011

ChevyDriver
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" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE
I noticed that Message-ID: <Rq3ze.625$[Email Removed]> from
ChevyDriver contained the following:

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.

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'];
}

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

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



--
Geoff Berrow  0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011


Geoff Berrow
I noticed that Message-ID: <UyHze.9889$[Email Removed]> from
ChevyDriver contained the following:

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


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


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.