ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

PHP Code Example for if-else Statement With Notepad++

Updated on August 3, 2012

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

	<form method = "post" action = "ifelsestatement.php">
			<td>Enter Your Name:</td>  
			<td><input type = "text" name = "name" /></td>
			<td>Enter Year of Birth:</td>  
			<td><input type = "text" name = "year" /></td>
			<td>Enter Month of Birth:</td>  
			<td><input type = "text" name = "month" /></td>
			<td>Enter Date of Birth:</td>  
			<td><input type = "text" name = "date" /></td>
			<td><input type = "submit" name = "submit" value="SUBMIT"/></td>

form2.html Sample Output

PHP Code Example on ifelsestatement.php

	$name = $_POST['name'];
	$year = $_POST['year'];
	$month = $_POST['month'];
	$date = $_POST['date'];
		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;
			if(date("m") < $month)
				$age = (date("Y") - $year) - 1;
				echo "Your current Age is: ".$age." yrs. Old.";
				$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


    0 of 8192 characters used
    Post Comment

    No comments yet.