- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming»
- Programming Languages
PHP Code Example for if-else Statement With Notepad++
PHP examples, PHP code examples on if-else statement
Another PHP code example for php programming enthusiasts. This hub will contain a php example code and output how the php codes work. If you do not know how to run an html file in your browser better read this hub on how to do it. Also, if you do not know how to run a php code, follow the steps on this hub to be able to test and run the php code example.
Note: The the php file which is named ifelsestatement.php is connected to an html file which is named form2.html. Better save the files with this name too.
form2.html Sample Code
<html> <form method = "post" action = "ifelsestatement.php"> <table> <tr> <td>Enter Your Name:</td> <td><input type = "text" name = "name" /></td> </tr> <tr> <td>Enter Year of Birth:</td> <td><input type = "text" name = "year" /></td> </tr> <tr> <td>Enter Month of Birth:</td> <td><input type = "text" name = "month" /></td> </tr> <tr> <td>Enter Date of Birth:</td> <td><input type = "text" name = "date" /></td> </tr> <tr> <td></td> <td><input type = "submit" name = "submit" value="SUBMIT"/></td> </tr> </table> </form> </html>
form2.html Sample Output
PHP Code Example on ifelsestatement.php
<?php $name = $_POST['name']; $year = $_POST['year']; $month = $_POST['month']; $date = $_POST['date']; if($_POST['submit']) { echo "Your Name is: ". $name."<br/>"; echo "Your birthday is on: ". $year."-".$month."-".$date."<br /><br />"; echo "Today's date is: ".date("Y-m-d")."<br /><br />"; if(date("d") == $date && date("m") == $month) { echo "OMG! Today is your birthday! <br />" ; echo "I wish you a happy birthday ".$name; } else { if(date("m") < $month) { $age = (date("Y") - $year) - 1; echo "Your current Age is: ".$age." yrs. Old."; } else { $age = (date("Y") - $year); echo "Your current Age is: ".$age." yrs. Old"; } } } ?>
ifelsestatement.php Sample Output
General Guide For Beginners on Running the Code Above:
1. Install Xaamp and notepad++
2. Open Xaamp and run MY SQL and Apache and open also Notepad++
3. Copy and past the form2.html to notepad++ and save it to drive where you installed your Xaamp, open the Xaamp folder, open the htdocs folder and the html file as form2.html.
4. Copy and paste the ifelsestatement.php to notepad++ and do the previous step. Save it with ifelsestatement.php.
5. Go to your browser and type this: localhost/form2.html
Other PHP Code Samples and Tutorials
- How to become a PHP Developer: Learn and Earn
- Steps on How to Program in PHP: A Beginner's Guide on PHP Programming-Part 1
- How to run PHP Code or PHP Scripts and See the Result on Your Browser
- HTML Basics: Learn The Basics of HTML and Create Your Own Webpage on Your Browser
- PHP Code Example on Associative Array and Multidimensional Array
- PHP Sample Codes On Function:How to make Function in PHP
- PHP code Example for if statement
- PHP Code Example on if else-if Statement
- PHP Code Example on Switch Statement
- PHP Code Example on While Loop
- PHP Code Example on Numeric Array
- PHP Code Example on Do-while Loop
- PHP Code Example on Foreach Loop and For Loop