- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming»
- Programming Languages
Sample PHP code Programs for if statement
PHP Code Example, PHP Scripts Sample, PHP Conditional Statements, PHP if Statement code sample
Do you wisth to see more php code examples? This hub contains php code example in if statement which is connected to a html file. Do you know how to run an html file in your browser? if not see this hub that illustrate on how to run an html file in your browser. See how the codes works! If you do not know how to run a PHP code on your browser please read this hub too.Also, to facilitate better understanding, in every PHP code examples provided, there will be a sample output after the code.
Note: Remember the php file is connected to form.html. They connected with an action to the form that indicated its file name. Save the two group of codes given on drive C (where you installed your Xaamp)-> XAAMP folder->htdocs folder. To avoid confusion below is the suggested file name for each of them.
ifstatement.php – for if statement PHP code example
form.html - for the html file
To run the file just type on your browser this: localhost/form.html and see how it works!
Sample code for form.html
<html> <form method = "post" action = "ifstatement.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>
Sample Output of the Code Above
PHP Code Example for ifstatement.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; } } ?>
Sample Output for ifstatement.php
See it for yourselves and run it on your own browser.For more clarifications, if you are a beginner, just follow the steps below.
Granted that you already installed XAAMP, openned the Xaamp and run apache and mysql and also installed notepad++ editor.
1. Copy and paste the form.html to notepad++ and save to the drive where your XAAMP is installed, look for Xaamp folder, click it and look for htdocs folder and click it and save it there.
2. Copy and paste the ifstatement .php to notepad++ and do the previous step.
3. Go to your browser and type this: localhost/html.php
4. You should be directed to the blank form of form.html, enter to the form and hit enter. That is how it runs.
More PHP Code Example and Tutorials
- Steps on How to Program in PHP: A Beginner's Guide on PHP Programming-Part 1
- How to become a PHP Developer: Learn and Earn
- 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 Sample Codes On Function:How to make Function in PHP
- PHP Code Example on Associative Array and Multidimensional Array
- PHP Code Example on Foreach Loop and For Loop
- PHP Code Example for if-else 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