If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Undefined variable error

Hi,
I've just bought the book PHP and MYSQL Web Development and have started to work through the examples. I'm running Linux Mint 14 with an Apache server. I installed PHP and MYSQL using Apache Friends. The server is started and simple PHP programs are working correctly. Code is saved to a 'tutorials' folder in apache htdocs using eclipse with the php plug-in.
I started a new php project in eclipse and added two files to the project. the first is an html file which I have called index.html. This is the code:

These examples are copied direclty from the book.
Line 5 in the html code

Code:

<table border="0">

is generating a warning in eclipse and i get the following error when i run localhost/tutorials. Here is the error generated:

Code:

Bob's Auto Parts
Order Results
Order processed at 22:38, 18th January
Your order is as follows:
Notice: Undefined variable: tireqty in /opt/lampp/htdocs/tutorials/processorder.php on line 13
tires
Notice: Undefined variable: oilqty in /opt/lampp/htdocs/tutorials/processorder.php on line 14
bottles of oil
Notice: Undefined variable: sparkqty in /opt/lampp/htdocs/tutorials/processorder.php on line 15
spark plugs
Notice: Undefined variable: tireqty in /opt/lampp/htdocs/tutorials/processorder.php on line 21
Notice: Undefined variable: oilqty in /opt/lampp/htdocs/tutorials/processorder.php on line 21
Notice: Undefined variable: sparkqty in /opt/lampp/htdocs/tutorials/processorder.php on line 21
Items ordered: 0
Notice: Undefined variable: tireqty in /opt/lampp/htdocs/tutorials/processorder.php on line 31
Notice: Undefined variable: oilqty in /opt/lampp/htdocs/tutorials/processorder.php on line 32
Notice: Undefined variable: sparkqty in /opt/lampp/htdocs/tutorials/processorder.php on line 32
Subtotal: $0.00
Total including tax: $0.00

Can anyone help with these errors. Code is exactly as listed in the book.

Users who have thanked AndrewGSW for this post:

Answer: toss your book. Its too old to work with (now 4.5 years old).
The error on an html element in eclipse is likely the use of deprecated HTML (border in table). Use CSS.
The problem with the PHP is it expects you have register_globals enabled. This directive has been disabled by default since 4.2, deprecated in 5.3, and removed in 5.4. As pointed out, all of your data must be extracted from a superglobal, which in this case is $_POST. You can however use isset() to check multiple conditions by giving all the arguments you expect, then within that block extract all the variables and process per normal.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

Thanks for the replies everyone. The problem seems to have been that the script on the CD had missing code from it. By following the example in the book itself, I added the following code and got it to work: