Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP : Validating forms and loops. Some things for helping you to validate input  The isset function can be used to test if a php variable is passed.

Similar presentations


Presentation on theme: "PHP : Validating forms and loops. Some things for helping you to validate input  The isset function can be used to test if a php variable is passed."— Presentation transcript:

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 "; $num++; } $num = 1; do while { echo "This loop is executed $num times "; $num++; } ($num < 10)

5 Loops: for Loops for ($num=0; $num " } You can terminate explicitly with a break statement. $desired = 10; for ($num=0; $num<100; $i++) { echo "The loop is on iteration: $num " 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. (a) 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 " "; or  echo " ";


Download ppt "PHP : Validating forms and loops. Some things for helping you to validate input  The isset function can be used to test if a php variable is passed."

Similar presentations


Ads by Google