PHP : Validating forms and loops - PowerPoint PPT Presentation

About This Presentation
Title:

PHP : Validating forms and loops

Description:

Title: HTML and Web Pages Author: Terence T. Ow Last modified by: Terence T. Ow Created Date: 1/5/2006 7:26:27 PM Document presentation format: On-screen Show – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 9
Provided by: Teren150
Category:

less

Transcript and Presenter's Notes

Title: PHP : Validating forms and loops


1
PHP Validating forms and loops
2
Some things for helping you to validate input
  • The isset function can be used to test if a php
    variable is passed.
  • If the variable _POST'firstName' contains a
    value then isset(_POST'firstName') would
    evaluate to true.
  • The is_numeric function may be useful during
    input validation to determine if the user entered
    a legitimate number.
  • if you are expecting a number to be typed into an
    HTML form field named age then is_numeric(_POST'
    age' would evaluate to true

3
Some things for helping you to validate input
  • The empty function can be used to test if a php
    variable contains a value or not.
  • If the variable _POST'firstName' contains a
    value then empty(_POST'firstName') would
    evaluate to false.
  • Other validation include
  • is_string(variableName)
  • is_float(variableName)
  • is_bool(variableName)
  • is_int(variableName)

4
Loops while and do-while
  • num 1
  • while (num lt 10)    echo "This loop is
    executed num timesltbr /gt"   num
  • num 1
  • do while    echo "This loop is executed num
    times ltbr /gt"   num
  • (num lt 10)

5
Loops for Loops
  • for (num0 num lt 10 num)    echo "This
    loop is executed num timesltbr /gt"
  • You can terminate explicitly with a break
    statement.
  • desired 10
  • for (num0 numlt100 i)
  • echo "The loop is on iteration num ltbr /gt"
  • if (num desired)
  • echo "Found desired"
  • break // if you reach this part, then the loop
    is broken

6
pex4.html, pex4.php
  • Redo ie. loan calculator so that

7
Formula for amortization table
  • Once you calculate the monthly payment, M, which
    stays the same.
  • The interest payment, IP O I
  • where O is the outstanding loan I is the
    monthly interest rate
  • (b) Principle Paid For, P, is the amount of
    loan that went to
  • principle rather than interest P M IP
  • (c) The new outstanding loan, O will now be
  • O O P
  • ie. Previous Outstanding balance Principle
    Paid For
  • Repeat the above steps (a) to (c) you need
    LOOP here to determine all periods.

8
Formatting and toggling
  • PHP allows up to round off numbers e.g.
  • num 2.467
  • num round(num, 2) // num should now
    displayed as 2.47
  • Next How to do alternate colors? There is a
    concept call modulus or sometimes call quotient.
    i.e. (num 2) means take num and divided by 2
    and tell me the remainder. So the remainder would
    be 0 or 1. If it is 0 you can do one thing like
    print the current row in blue and if it is 1 you
    can print the row in gold. How to do that in php?
  • echo "ltTR bgcolorbluegt" or
  • echo "ltTR bgcoloryellowgt"
Write a Comment
User Comments (0)
About PowerShow.com