p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Chapter 8 pg 268


Message #1 by "Bjorn Tipling" <swartkrans@m...> on Wed, 24 Apr 2002 14:25:46
okay I'm getting a headache trying to figure this out.. please help me 

I'm getting this error:

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in c:\program
files\apache group\apache\htdocs\menu2.php on line 19

and this is my complete code for the exercise:

menu1.php
=========
<html>
<head><title>Welcome to Charlie's</title></head>
<body>
<?php
$Entrees=array("Steak ($9)", "Pizza ($7)", "Pasta ($6)");

echo "<form method=post action ='menu2.php'>";
echo "Which of the following would you like as an entree?";
echo "<select name='PERS_Entree'>";
echo "<option selected value=''>Select...</option>";
echo "<option>$Entrees[0]</option>";
echo "<option>$Entrees[1]</option>";
echo "<option>$Entrees[2]</option>";
echo "<select><br /><br />";
echo "<input type='submit'>";
echo "</form>";
?>
</body>
</html>

menu2.php
=========
<html>
<head><title>Welcome to Charlie's dessert selection</title></head>
<body>
<?php

$Desserts=array("Apple Pie ($3)","Pancakes ($3)","Ice Cream ($2)");

echo "<form method='post' action='bill.php'>";
echo "Which of the following would you like as a dessert?";
echo "<select name='PERS_Dessert'>";
echo "<option selected value=''>Select...</option>";
echo "<option>$Desserts[0]</option>";
echo "<option>$Desserts[1]</option>";
echo "<option>$Desserts[2]</option>";

echo "</select><br /><br />";

if ($HTTP_POST_VARS) {
	while (list($1var, $1value) = each($HTTP_POST_VARS)) {   //LINE 19
		if (ereg ("^PERS_", $1var, $throwaway) ) {
			echo "<input type='hidden' name='$1var' value='$1value'>\n";
		}
	}
}

echo "<input type='submit'>";
echo "</form>";
?>
</body>
</html>

bill.php
========
<html>
<head><title>Thank you for dining at Charlie's</title></head>
<body>

<?php
$total = 0;

echo "Your order was for the following:<br /><br />";

if ($HTTP_POST_VARS) {
	while (list($1var, $1value) = each($HTTP_POST_VARS)) {
		if (ereg("^PERS_", $1var, $throwaway) ^ 0) {
			echo "$1var: $1value<br />";
			if (ereg("[0-9]+", $1value, $regs)) $total += $regs[0]; }
	}
}

echo "TOTAL BILL =$". $total . "<br />";

?>
</body>
</html>


Ive checked it a million times, and I just checked this to make sure I did
it correct, but I'm still getting the error :(
Message #2 by "Bjorn Tipling" <swartkrans@m...> on Wed, 24 Apr 2002 14:27:51
sorry thats page 270 actually...
Message #3 by "Bjorn Tipling" <swartkrans@m...> on Wed, 24 Apr 2002 14:31:50

	if (ereg("^PERS_", $1var, $throwaway) > 0) {

okay I fixed that, but it still not working and it wont even get to this page
	
Message #4 by "Bjorn Tipling" <swartkrans@m...> on Wed, 24 Apr 2002 14:54:09
AHA! i fixed it. oooooooooohhhh the book is so wrong   >:(

you cant have variables that start with digits! 

you need an errata! >:(

well, the good thing is I'll never forget that variables cant start with
digits... 

mebbe somebody should let the author know :P
Message #5 by "Nikolai Devereaux" <yomama@u...> on Wed, 24 Apr 2002 09:49:06 -0700
> AHA! i fixed it. oooooooooohhhh the book is so wrong   >:(
>
> you cant have variables that start with digits!
>
> you need an errata! >:(
>
> well, the good thing is I'll never forget that variables cant start with
> digits...
>
> mebbe somebody should let the author know :P

Chances are the author does know.


> menu1.php
   ...
> $Entrees=array("Steak ($9)", "Pizza ($7)", "Pasta ($6)");

These looks like prices, not variables.  The strings should be single quoted
to prevent PHP from thinking that $9, $7 and $6 are variables.

Again:

> menu2.php
   ...
> $Desserts=array("Apple Pie ($3)","Pancakes ($3)","Ice Cream ($2)");

same thing.


> if ($HTTP_POST_VARS) {
> 	while (list($1var, $1value) = each($HTTP_POST_VARS)) {   //LINE 19
> 		if (ereg ("^PERS_", $1var, $throwaway) ) {
> 			echo "<input type='hidden' name='$1var'
> value='$1value'>\n";
> 		}
> 	}

This looks bad.  $1var and $1value are clearly variables, and if the author
wrote them in the book like this, then that's horrible.  Unforgivable.  Why
didn't I get the book deal?  I've always wanted an unflattering B&W picture
of me plastered on a big red book.

> if ($HTTP_POST_VARS) {
> 	while (list($1var, $1value) = each($HTTP_POST_VARS)) {
> 		if (ereg("^PERS_", $1var, $throwaway) ^ 0) {
> 			echo "$1var: $1value<br />";
> 			if (ereg("[0-9]+", $1value, $regs)) $total
> += $regs[0]; }
> 	}


OOOO  OOOO THE PAIN!!  Stop it now!!


nik



Message #6 by "Gen Goku" <goku@s...> on Mon, 29 Apr 2002 23:31:39
> 
> AHA! i fixed it. oooooooooohhhh the book is so wrong   >:(

Yes, i've encountered many errors in the book, but I wouldn't expect 
perfection on a first ed. book unless they've got editors that actually 
try out the samples before giving the 'ok!'

p128 
- note that with else [i think he means 'if'] and...

p109 
- chapter overview tricked me -- there is NO 'include files' in there

p177 (paragraph 2)
- "php navigate...no matter which order populated." AFAIK this is false 
when he was talking about next() and prev()

p178
- asort() sample shows wrong order - il had sacramento as the capital!

p186 line 11
- grammar error; "As" was capitalized

misc
- grammar is wrong; they have all "periods on the outside of quotes like 
this".

- code is not consistant. some show echo ("with parens"); and 
echo "without parens";

don't get me wrong, i like the structure of the book (overview, 
explination of tools, sample, and finally how the sample works) and think 
it's great. i just wish the editors took more time to check that 
everything was right.

  Return to Index