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 November 3rd, 2003, 01:07 PM
Authorized User
 
Join Date: Oct 2003
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.";
?>


 
Old November 3rd, 2003, 02:29 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 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
:::::::::::::::::::::::::::::::::





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 01: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 09: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 11: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 08:46 PM





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