p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Chapter 3 - Loan Application Form


Message #1 by "David M. Dickerson" <dmdickerson@s...> on Tue, 11 Feb 2003 05:11:56
Hello, everyone.

I am having trouble with the loan application form beginning on page 100 
of BEGINNING PHP.

I am sure that I have made a typographical error, either in the PHP file 
or the HTML file, but I simply cannot see my mistake(s).

My 'loan.html' file is as follows (and I have made some changes from the 
book so that the code complies with W3C standards, such as making tag 
names in lower-case letters):

<html>
<head>
  <title>Loan Application Form</title>
</head>
<body>
<h1 align="center">Namllu Credit Bank<br>Loan Application Form</h1>

<form method=post action="loan.php">
First Name:
<input name="FirstName" type="Text">

Last Name:
<input name="LastName" type="Text">

Age:
<input name="Age" type="Text" size="3">
<br>
<br>

Address
<textarea name="Address" rows="4" cols="40">
</textarea>
<br>
<br>

What is your current salary?
<select name="Salary">
<option value=0>Under $10000</option>
<option value=10000>$10000 to $25000</option>
<option value=25000>$25000 to $50000</option>
<option value=50000>Over $50000</option>
</select>
<br>
<br>

How much do you want to borrow?<br><br>
<input name="Loan" type="Radio" value=1000>Our $1,000 package at 8.0% 
interest
<br>
<input name="Loan" type="Radio" value=5000>Our $5,000 package at 11.5% 
interest
<br>
<input name="Loan" type="Radio" value=10000>Our $10,000 package at 15.0% 
interest
<br>
<br>

<input type=submit value="Click Here to Submit Application">
<input type=reset value="Click Here to Reset Application Form">
</form>

</body>
</html>

My 'loan.php' file is as follows:

<html>
<head>
  <title>Loan Application Form</title>
</head>
<body>
<h1 align="center">Namllu Credit Bank<br>Loan Application Form</h1>
<br>
<br>

<?php
$SalaryAllowance = $Salary/5;
$AgeAllowance = ($Age/10 - ($Age%10)/10)-1;
$LoanAllowance = $SalaryAllowance * $AgeAllowance;
echo "Loan wanted:$Loan<br>";
echo "Loan amount we will allow: $LoanAllowance<br><br>";
if ($Loan <= $LoanAllowance) echo "Yes, $FirstName $LastName, we are 
delighted to accept your application.";
if ($Loan > $LoanAllowance) echo "Sorry, $FirstName $LastName, we are 
cannot accept your application at this time.";.";
?>

</body>
</html>

I would be grateful for any suggestions. Thank you, very much, in advance!

Cordially,

David
--
http://ddickerson.igc.org/

P.S. -- One problem I have is that my <textarea> will not allow me to hit 
RETURN to type each individual address line. I am very puzzled by this 
error!
Message #2 by "David Smith" <dave@c...> on Tue, 11 Feb 2003 09:29:58
> <html>
<> head>
 >  <title>Loan Application Form</title>
<> /head>
<> body>
<> h1 align="center">Namllu Credit Bank<br>Loan Application Form</h1>

> <form method=post action="loan.php">
F> irst Name:
<> input name="FirstName" type="Text">

> Last Name:
<> input name="LastName" type="Text">

> Age:
<> input name="Age" type="Text" size="3">
<> br>
<> br>

> Address
<> textarea name="Address" rows="4" cols="40">
<> /textarea>
<> br>
<> br>

> What is your current salary?
<> select name="Salary">
<> option value=0>Under $10000</option>
<> option value=10000>$10000 to $25000</option>
<> option value=25000>$25000 to $50000</option>
<> option value=50000>Over $50000</option>
<> /select>
<> br>
<> br>

> How much do you want to borrow?<br><br>
<> input name="Loan" type="Radio" value=1000>Our $1,000 package at 8.0% 
i> nterest
<> br>
<> input name="Loan" type="Radio" value=5000>Our $5,000 package at 11.5% 
i> nterest
<> br>
<> input name="Loan" type="Radio" value=10000>Our $10,000 package at 15.0% 
i> nterest
<> br>
<> br>

> <input type=submit value="Click Here to Submit Application">
<> input type=reset value="Click Here to Reset Application Form">
<> /form>

> </body>
<> /html>

> My 'loan.php' file is as follows:

> <html>
<> head>
 >  <title>Loan Application Form</title>
<> /head>
<> body>
<> h1 align="center">Namllu Credit Bank<br>Loan Application Form</h1>
<> br>
<> br>

> <?php
$> SalaryAllowance = $Salary/5;
$> AgeAllowance = ($Age/10 - ($Age%10)/10)-1;
$> LoanAllowance = $SalaryAllowance * $AgeAllowance;
e> cho "Loan wanted:$Loan<br>";
e> cho "Loan amount we will allow: $LoanAllowance<br><br>";
i> f ($Loan <= $LoanAllowance) echo "Yes, $FirstName $LastName, we are 
d> elighted to accept your application.";
i> f ($Loan > $LoanAllowance) echo "Sorry, $FirstName $LastName, we are 
c> annot accept your application at this time.";.";
?> >

> </body>
<> /html>

> I would be grateful for any suggestions. Thank you, very much, in 
advance!

> Cordially,

> David
-> -
h> ttp://ddickerson.igc.org/

> P.S. -- One problem I have is that my <textarea> will not allow me to 
hit 
R> ETURN to type each individual address line. I am very puzzled by this 
e> rror!

I have no idea why you should be having problems with the textarea tag, 
I;ve just tried it, and it works ok here.

You do have problems with the php file though.

In the last few lines of code:

  if ($Loan <= $LoanAllowance) echo "Yes, $FirstName $LastName, we are 
  delighted to accept your application.";
  if ($Loan > $LoanAllowance) echo "Sorry, $FirstName $LastName, we are 
  cannot accept your application at this time.";.";
  ?>

should read

  if ($Loan <= $LoanAllowance) { echo "Yes, $FirstName $LastName, we are 
  delighted to accept your application."; }
  if ($Loan > $LoanAllowance) { echo "Sorry, $FirstName $LastName, we are 
  cannot accept your application at this time."; }
  ?> 

You forgot the { and added ."; twice to the second if statement.

Although the code works without { , it's still better practise to use them.
Message #3 by "Nikolai Devereaux" <yomama@u...> on Tue, 11 Feb 2003 12:53:27 -0800

First of all, you should be aware that you're coding your site with the
assumption that register_globals is on.  It's probably not.

Read http://p2p.wrox.com/archive/beginning_php/2002-11/17.asp for more info.


> In the last few lines of code:
>
>   if ($Loan <= $LoanAllowance) echo "Yes, $FirstName $LastName, we are
>   delighted to accept your application.";
>   if ($Loan > $LoanAllowance) echo "Sorry, $FirstName $LastName, we are
>   cannot accept your application at this time.";.";
>   ?>
>
> should read
>
>   if ($Loan <= $LoanAllowance) { echo "Yes, $FirstName $LastName, we are
>   delighted to accept your application."; }
>   if ($Loan > $LoanAllowance) { echo "Sorry, $FirstName $LastName, we are
>   cannot accept your application at this time."; }
>   ?>
>
> You forgot the { and added ."; twice to the second if statement.
>
> Although the code works without { , it's still better practise to use them.


As long as you're talking about good practice, you should fix your indentation
and grammar.  Also, it's inefficient to recompare $Loan and $LoanAllowance in
a second if.

After all, if the first if() stmt fails, the second MUST be true.  Use else
instead.


Rewritten:

if($Loan <= $LoanAllowance)
{
   echo "Yes, $FirstName $LastName, we are delighted "
      . " to accept your application.";
}
else
{
   echo "Sorry, $FirstName $LastName
}


Take care,

Nik

Message #4 by "David M. Dickerson" <dmdickerson@s...> on Thu, 13 Feb 2003 01:24:15
Hi, David.

Thank you for your message.

You write:

> You forgot the { and added ."; twice to the
> second if statement.

> Although the code works without { , it's still
> better practise to use them.

I deleted the extra text and I added the '}' brackets.

Unfortunately, I still am having problems with the <textarea> tag. I 
cannot get a carriage return to move the cursor to the next line. I am 
totally baffled!

I appreciate the tip about the brackets, David. They are not in BEGINNING 
PHP 4, but perhaps they will be introduced later in the book.

The <textarea> is really what is bothering me now.

Again, David, thanks!

Cordially,

David
Message #5 by "David M. Dickerson" <dmdickerson@s...> on Thu, 13 Feb 2003 01:31:56
Hi, Nik.

Thank you for your message.

> First of all, you should be aware that you're coding your
> site with the assumption that register_globals is on.
> It's probably not.

Actually, 'register_globals' is on. :-)

> Read http://p2p.wrox.com/archive/beginning_php/2002-11/17.asp
> for more info.


> As long as you're talking about good practice, you should fix
> your indentation and grammar.  Also, it's inefficient to recompare
> $Loan and $LoanAllowance in a second if.
> 
> After all, if the first if() stmt fails, the second MUST be
> true.  Use else instead.

Ironically, I am typing in the code from Wrox's BEGINNING PHP 4. I am 
a "total newbie" to PHP, Nik, so I have to trust the book when it comes to 
the PHP and HTML code examples. (I cannot do what I do not yet know how to 
do, in other words.) ;-)

> Rewritten:
> 
> if($Loan <= $LoanAllowance)
> {
>    echo "Yes, $FirstName $LastName, we are delighted "
>       . " to accept your application.";
> }
> else
> {
>    echo "Sorry, $FirstName $LastName
> }

Thanks for the tip, Nik.

I still am baffled about the <textarea> problem, no do I get any results 
when I submit a loan request via the HTML page, the code of which I copied 
from the book. My browser just gives me a blank page.

Thanks again, Nik. I am truly "stuck" on this simple example!

Cordially,

David
Message #6 by "David M. Dickerson" <dmdickerson@s...> on Fri, 14 Feb 2003 07:02:07
Hello, everyone.

My HTML and PHP code are not the problem.

I have discovered a bug in my PHP Editor, DzSoft PHP Editor 1.2, and a fix 
is on the way. The bug is in the editor's built-in Web browser.

I just wanted to clear up this matter and to let everyone know that the 
code is okay.

For the time being, I will save my PHP and related HTML files to 
the 'htdocs' folder and access them on 'localhost'.

Thank you for your time and help!

Cordially,

David
--
http://ddickerson.igc.org/
Message #7 by "Nikolai Devereaux" <yomama@u...> on Thu, 13 Feb 2003 23:39:53 -0800
> My HTML and PHP code are not the problem.
> 
> I have discovered a bug in my PHP Editor, DzSoft PHP Editor 1.2, and a fix 
> is on the way. The bug is in the editor's built-in Web browser.


DOH!  That sucks!  I'm glad to hear that it's all figured out, though.


Nik



  Return to Index