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.

Slides:



Advertisements
Similar presentations
Building an Amortization Schedule How the banks do it and what we need to know…
Advertisements

Solving Problems with Repetition. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C# program Correctly.
CS0004: Introduction to Programming Repetition – Do Loops.
ITC 240: Web Application Programming
Computer Science 1620 Loops.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
Topic 6 – Repetition and Loops. CISC 105 – Topic 6 Program Repetition Repetition refers to the repeats of certain program statements within a program.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
CS Sept 2006 Pick ups from chapters 4 and 5.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
CS 1400 Pick ups from chapters 4 and 5. if-else-if Chained if statements can be useful for menus… Enter savings plan choice: (A) economy rate (B) saver.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Loops – While, Do, For Repetition Statements Introduction to Arrays
CS 1400 Pick ups from chapters 4 and 5. if-else-if Chained if statements can be useful for menus… Enter savings plan choice: (A) economy rate (B) saver.
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
More Looping Structures
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
1 Copyright (C) 2008 by Dennis A. Fairclough all rights reserved.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 4 Objectives  Learn about repetition (looping) control structures.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
If statements while loop for loop
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
1 Chapter 9 Additional Control Structures Dale/Weems.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Loop.  While Loop  Do-while Loop  For Loop Continue Statement Conclusion Loop Loop.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
A First Book of C++ Chapter 5 Repetition.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Chapter Looping 5. The Increment and Decrement Operators 5.1.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Chapter 6: Looping. Objectives Learn about the loop structure Create while loops Use shortcut arithmetic operators Create for loops Create do…while loops.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
Solving Problems with Repetition Version 1.0. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C#
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Loops BIS1523 – Lecture 10.
PROGRAM CONTROL STRUCTURE
Learning About the Loop Structure (continued)
Arrays, For loop While loop Do while loop
Conditions and Ifs BIS1523 – Lecture 8.
In Class Programming BIS1523 – Lecture 11.
Alternate Version of STARTING OUT WITH C++ 4th Edition
ECS15 while.
A LESSON IN LOOPING What is a loop?
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Presentation transcript:

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. 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

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)

Loops: while and do-while $num = 1; while ($num "; $num++; } $num = 1; do while { echo "This loop is executed $num times "; $num++; } ($num < 10)

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 }

pex4.html, pex4.php  Redo ie. loan calculator so that

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.

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 " ";