Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 3rd, 2003, 12:07 PM
Authorized User
 
Join Date: Oct 2003
Location: , Ok, .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default CH 4 Pg 143 HTMLSpecialChars

I have a little problem.

When I test my form ( this is working with the Loan page, checking to see if fields are filled in properly), it correctly removed the html characters I entered into the name field but, the age field is incorrect.

Notice down on the first "if" field. I added "You entered: " to this script because no matter what number I entered it always says go back. I do not know why. For example, if you enter in 25, which is above and below the accpeted limits, my page says "You entered: age".

It is printing out the name of the variable, not the variable itself.


<?php
    $_POST["firstname"] = HTMLSpecialChars("firstname") ;
    $_POST["lastname"] = HTMLSpecialChars("lastname") ;
    $_POST["age"] = HTMLSpecialChars("age") ;
    $_POST["address"] = HTMLSpecialChars("address") ;

    if ($_POST["age"] < 10 or $_POST["age"] > 140)
    {
        echo "Your entered: $_POST[age] <br />";
        echo "Incorrect Age entered - Press back button to try again.";
        exit;
    }
    if ($_POST["firstname"] == "" or $_POST["lastname"] == "")
    {
        echo "You must enter you name - Press back button to try again.";
        exit;
    }
    if ($_POST["address"] = "")
    {
        echo "You must enter your address - Press back button to try again.";
        exit;
    }
    if ($_POST["loan"] != 1000 and $_POST["loan"] != 5000 and $_POST["loan"] = 10000)
    {
        echo "You must enter a loan value - Press back button to try again.";
        exit;
    }


    $SalaryAllowance = $_POST["salary"] / 5;
    $AgeAllowance = ($_POST["age"] / 10 - ($_POST["age"] % 10) / 10 ) -1;
    $LoanAllowance = $SalaryAllowance + $AgeAllowance;

    echo "Loan desired: $_POST[loan] <br /> " ;
    echo "Loan amount we will allow: $LoanAllowance <br /><br />";
        if ($_POST["loan"] <= $LoanAllowance) echo "Yes, $_POST[firstname] $_POST[lastname], we are delighted to accept your application. ";
        if ($_POST["loan"] > $LoanAllowance) echo "We\"re sorry, $_POST[firstname] $_POST[lastname], we cannot accept your application at this time.";
?>


Reply With Quote
  #2 (permalink)  
Old November 3rd, 2003, 01:29 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Well you're going about this the wrong way..

In this statement you are passing the literal string "firstname" to the htmlspecialchars() function. So that string will be assigned to $_POST["firstname"]
$_POST["firstname"] = HTMLSpecialChars("firstname");

Instead write:

$_POST["firstname"] = HTMLSpecialChars($_POST["firstname"]);

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 5 Arrays Pg 134 Sadlowski BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 February 23rd, 2006 12:25 PM
Ch 2 pg 24 "Using the Properties..." LuluDev BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 January 23rd, 2006 08:12 AM
CH 3 pg 96 Question mririe BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 8 August 25th, 2004 04:17 AM
CH 5 pg 160 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 8 November 12th, 2003 10:23 PM
CH 3 pg 76 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 26th, 2003 07:46 PM



All times are GMT -4. The time now is 09:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.