473,734 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keep getting undefined variable errors - please help

hello,

i am new to PHP, so go easy.

I am using the examples in the book:
PHP: Your Visual Blueprint For Creating Open Source, Server Side Content

In the section where they talk about getting values from a form
submission, the book says:

"PHP makes it easy to process data from a form. When a PHP
page receives form information, the page automatically converts
the names of form elements to PHP variables, and assigns
the data entered in the elements to the variables"

So I try to display what was submitted, but I get an undefined
variable error.

For example,

<? php
print "the ID you entered was: ";
print $userid;
?>

This returns an error. But, if I use the following it works:

<? php
print "the ID you entered was: ";
print $HTTP_POST_VARS['userid'];
?>

Can someone explain this?

One more example:

I'm trying to simply display a session ID (using the example in the book):

<?php
session_start() ;
?>

<html>
<head>
<title>PHP Session Test</title>
</head>
<body>

<?php
print "The session ID is: ";
print $PHPSESSID;
?>

</body>
</html>

When I access this page I get:

The session ID is:
Notice: Undefined variable: PHPSESSID in c:\inetpub\wwwr oot\sessiontest .php
on line 13

Why do I get this error? This is the exact example from the book.

Please post replies to the newsgroup rather than a direct e-mail.
Thanks for your help.




Jul 17 '05 #1
3 6120
On Wed, 28 Jul 2004 03:45:36 +0000, Jason wrote:
hello,

i am new to PHP, so go easy.

I am using the examples in the book:
PHP: Your Visual Blueprint For Creating Open Source, Server Side Content

In the section where they talk about getting values from a form
submission, the book says:

"PHP makes it easy to process data from a form. When a PHP
page receives form information, the page automatically converts
the names of form elements to PHP variables, and assigns
the data entered in the elements to the variables"

So I try to display what was submitted, but I get an undefined
variable error.

For example,

<? php
print "the ID you entered was: ";
print $userid;
?>

This returns an error. But, if I use the following it works:

<? php
print "the ID you entered was: ";
print $HTTP_POST_VARS['userid'];
?>

Can someone explain this?

An old book =)

Since PHP4.2.0, the php.ini setting 'register_globa ls' has been disabled
by default (for security reasons). The method you want to use today is:
echo $_POST['userid'];
and from what I gather, to be PHP5 compliant too:
if (isset($_POST['userid'])) echo $_POST['user_id'];
but I haven't tried PHP5 myself as yet.

One more example:

I'm trying to simply display a session ID (using the example in the book):

<?php
session_start() ;
?>

<html>
<head>
<title>PHP Session Test</title>
</head>
<body>

<?php
print "The session ID is: ";
print $PHPSESSID;
?>

</body>
</html>

When I access this page I get:

The session ID is:
Notice: Undefined variable: PHPSESSID in c:\inetpub\wwwr oot\sessiontest .php
on line 13

Why do I get this error? This is the exact example from the book.

Please post replies to the newsgroup rather than a direct e-mail.
Thanks for your help.

Again due to register_global s.
session_start() ;
echo session_id();
Hit php.net and do a "search online documentation" for 'register_globa ls'
and 'superglobals' and you'll find the others too, such as $_GET,
$_SERVER, $_COOKIE, $_FILES, $_SESSION =)
HTH.

Regards,

Ian
PS: FWIW.. I'd scrap your book.. it's old and sounds like it will teach
you some poor coding habits (and obvious problems). After many years now
of coding in PHP, I've never once opened the cover of a book... php.net is
the best online reference I've come across for anything of its nature.

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
Red
Jason wrote:
hello,

i am new to PHP, so go easy.

I am using the examples in the book:
PHP: Your Visual Blueprint For Creating Open Source, Server Side Content

In the section where they talk about getting values from a form
submission, the book says:

"PHP makes it easy to process data from a form. When a PHP
page receives form information, the page automatically converts
the names of form elements to PHP variables, and assigns
the data entered in the elements to the variables"

So I try to display what was submitted, but I get an undefined
variable error.

For example,

<? php
print "the ID you entered was: ";
print $userid;
?>

This returns an error. But, if I use the following it works:

<? php
print "the ID you entered was: ";
print $HTTP_POST_VARS['userid'];
?>

Can someone explain this?
Sure, your book is out of date.
use $_POST['userid'] instead.
as in:$userid=$_PO ST['userid'].
For security purposes, resister globals are turned off by default in the
more recent versions of php
read about register globals
http://www.phpbuilder.com/manual/lan...predefined.php
One more example:

I'm trying to simply display a session ID (using the example in the book):

<?php
session_start() ;
?>

<html>
<head>
<title>PHP Session Test</title>
</head>
<body>

<?php
print "The session ID is: ";
print $PHPSESSID;
?>

</body>
</html>

When I access this page I get:

The session ID is:
Notice: Undefined variable: PHPSESSID in c:\inetpub\wwwr oot\sessiontest .php
on line 13

Why do I get this error? This is the exact example from the book.

Please post replies to the newsgroup rather than a direct e-mail.
Thanks for your help.



Jul 17 '05 #3
thanks for the reply. man that was frustrating. i just bought
a new book that covers php 5, and i'll be sure to check out
php.net

Can someone explain this?

An old book =)

Since PHP4.2.0, the php.ini setting 'register_globa ls' has been disabled
by default (for security reasons). The method you want to use today is:
echo $_POST['userid'];
PS: FWIW.. I'd scrap your book.. it's old and sounds like it will teach
you some poor coding habits (and obvious problems). After many years now
of coding in PHP, I've never once opened the cover of a book... php.net is
the best online reference I've come across for anything of its nature.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1731
by: Bill Godfrey | last post by:
Hello. Is there any way please I can make the PHP interpreter report "undefined variable" errors, instead of replacing unknown variables with nothing? Three times today, I've tracked an error down to using a non-existant variable which had arrived though a typo or a scoping error. Many thanks.
10
2319
by: Chuck | last post by:
Hi! Any ideas as to how I can get ride of the script error undefined variable "Exp_Month"? I am trying to get this drop down list to default to the current month as opposed to 01. Thank you in advance.
3
8020
by: lkrubner | last post by:
how does one set a variable so as to avoid errors like this: Notice: Undefined variable: arrayToCapture in /home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/McControllerForAll.php on line 922
3
2091
by: matro | last post by:
hi there, I'm using RegEx object with the string "(\)" to get arguments from a line like this: This line has got argument and one. the issue is that I obtain a MathCollection with "" and "".
0
1172
by: Tiraman | last post by:
Hi , i m getting the following errors under the eventlog while i m trying to run some class that i wrote. at the first i got an error about the just-in-time : access denied and i added the permissions as i read in some article but this didn't help to so i disable the JIT from the IDE properties and then i got those errors . please advice.
4
4085
by: cyberlei | last post by:
hi all, I`m getting this error Notice: Undefined index: user in c:\inetpub\wwwroot\login.php on line 96 Notice: Undefined variable: message in c:\inetpub\wwwroot\login.php on line 101 Could someone please tell me where I did wrong? Here is the Code, Thanks a lot <?php
1
1166
by: Oltmans | last post by:
Hi all, I've been writing C# code using Visual Studio 2005 for some time now but for the first time I've to write ANSI C code using Visual Studio 2005. I followed this article http://support.microsoft.com/kb/829488 that does a good job of explaining how to write ANSI C using Visual Studio 2005. When I write the following program it compiles and runs fine. I get the "Hello World" message shown in the command prompt. #include <stdio.h>
3
1348
by: nimamc | last post by:
I'm trying to test a class I have written(I'm an absolute beginner!). I'm getting these errors: These are the codes: Punt.java :
2
3762
by: norwichchris | last post by:
hi, I am having serious trouble with my PHP Postcard script. The error message i get is: Notice: Undefined index: Notice: Undefined variable Basically it does not send out the scripts at all. It is hosted on Awardspace. <?php session_start();
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.