Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2004, 09:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by bbforrester
 I did that and it still didn't work. I found a better solution, I returned the book and went back to the tried and true Sam's Publishing. Thanks for the input.

You're ignoring the problem, though. PHP won't suddenly start working properly because you're copying examples out of a different book. You're telling me that you can't turn register_globals off. That means that something's wrong with your PHP setup. The solution isn't burying your head in the sand about PHP configuration and installation issues...

I do admit that as a developer, you're much better off learning how to program PHP using error_reporting = E_ALL and register_globals = OFF. Since it's not up to you to administer the servers your scripts will run on, you should spend more of your time learning how to write PHP code than installing the interpreter.


Take care,

Nik
http://www.bigaction.org/
 
Old March 24th, 2004, 04:01 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code below is from beggining php4 book. As u said i did some changes to it.. and it seems doesnt works.. im a newbie.. so needs u guys help..thanks ya



<HTML>
<HEAD></HEAD>
<BODY>
<b>Namllu credit bank loan application form</b>
<br>
<br>
<?php
$SalaryAllowance=$Salary/5;
$AgeAllowance=($Age/10-($Age%10)/10)-1;
$LoanAllowance=$SalaryAllowance*$AgeAllowance;
echo "Loan wanted : $_POST["Loan"]";
echo "Loan amount we will allow: $_POST["LoanAllowance"]<br><br> ";

if($Loan <= $LoanAllowance) echo "Yes, $_POST["FirstName ", "$LastName"], we are delighted to accept ur aplication";
if($Loan > $LoanAllowance) echo "Sorry, $_POST["FirstName ", "$LastName"], we cannot accept your application at this time";
?>
</BODY>
</HTML>

 
Old March 24th, 2004, 06:47 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The only help that I can offer is to buy a new book. I tried to get help from Wrox and got a form letter response. I returned my book and got Teach Yourself PHP in 24 Hours by Sams Publishing. Best of luck.



Brian K. Forrester
 
Old March 24th, 2004, 07:49 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally post by bbforrester

The only help that I can offer is to buy a new book. I tried to get help from Wrox and got a form letter response. I returned my book and got Teach Yourself PHP in 24 Hours by Sams Publishing. Best of luck.
Complaining to the subscribers of this list isn't going to do you any good -- we're not Wrox/Wiley employees -- and this does nothing to help hongxxxx with his/her problem.

This problem relates to the register_globals setting. I *don't* own a copy of this book anymore, so I don't remember what all went into this exercise.

Here are my suggestions for successfully getting through this and future exercises.

1.) Do a little background research on what the register_globals setting _is_... Nik and I have answered a plethora of questions on the topic and likewise since the setting was made to 'off' by default, nearly every example in the book affected by this has been questioned by someone at one point or another on the p2p forums.

Search:
http://www.google.com/search?q=regis...e:p2p.wrox.com

2.) Once you understand what it is and what it does, turn it back on in php.ini so you can understand and progress through the book's exercises.

Open the php.ini configuration file.. This file is located in the Windows directory on a windows box, not sure where it is on linux.. but it can be opened with a plain text editor.

It would be found at C:\Windows or where ever windows is installed.

Find the line that looks like this:
register_globals = off

Replace it with:
register_globals = on

Find the error_reporting line and modify it to this:
error_reporting = E_ALL & ~E_NOTICE

Restart the HTTP server if necessary.
Now the enviornment of the book's authors is recreated.

Once you feel confident in your understanding of basic concepts, learn how to work with register_globals = off and error_reporting = E_ALL. As the former is a deprecated setting, meaning that future versions of PHP aren't required to support it. The latter provides a more detailed level of error_reporting.

Writing code to the old settings is no longer considered good practice. Is the Wrox book a bit dated? Yes! But that doesn't mean you can't still get some use out of it.

That being said, a word on your code:
$_POST["FirstName ", "$LastName"],

The $_POST variable is an array that is populated from the various input fields of a POST method HTML form. This array cannot hold a reference to more than one piece of data at the same time, so the above is not correct.. each indice must be referenced individually. The above should have resulted in a parse error.

Here is a working alternative...
echo "Yes, {$_POST['FirstName']} {$_POST['LastName']}, we are delighted to accept ur aplication";

This makes use of curly syntax which allows PHP to drop out of normal string parsing mode whereas the variable contained in curly braces will be substituted for the proper value. This is handy for arrays with multiple levels of nesting, object properties, or you guessed it, plain ole variables.

There are other ways of referencing variables as well..
Have a look at the PHP manual page on strings.
http://us4.php.net/manual/en/language.types.string.php

hth,
: )
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old March 29th, 2004, 04:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default


The other "simple" answer is to examine the script you're copying to determine which PHP variables contain values submitted via HTTP get or post data.

In the above case, $Salary, $Age, $Loan, $FirstName, and $LastName are all submitted via the form, so they should be replaced with $_POST['Salary'], $_POST['Age'], etc...


Take care,

Nik
http://www.bigaction.org/
 
Old May 3rd, 2004, 05:07 AM
Registered User
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found there were a few errors in the book and in the errata code on the Wrox website. However this has not caused too many problems. I found that where in one section an error may occur in the written code. Reading on makes things clearer. Then if I went back I could amend the code by finding and working out the error. I have learned more by this process than I did by blindly writing code from a book and expecting it to work. In time of error one must find solutions

Cheers
Lapidos






Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad SQL in Try It Out in chapter 3 punch BOOK: Beginning SQL 1 August 18th, 2006 06:39 PM
Chapter 12, Try It Out, p.454, bad TagPrefix VictorVictor BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 February 23rd, 2006 02:39 PM
Why session_register() is bad. nikolai Pro PHP 17 November 21st, 2004 09:35 PM
error codes, Chapter 8, Page 218 JohnAlden BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 June 19th, 2004 11:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.