VB icon

Display the result in the same page in PHP

Email
Submitted on: 11/26/2015 12:56:27 PM
By: Jake R. Pomperada  
Level: Beginner
User Rating: Unrated
Compatibility: PHP 3.0, PHP 4.0, PHP 5.0
Views: 7010
author picture
 
     In this sample program I would like to share with you how to create a program that will accept input values from the user and then display the values in PHP using the same page. The code is very simple and easy to understand ideal for beginners in PHP programming. If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Display the result in the same page in PHP
// Description:In this sample program I would like to share with you how to create a program that will accept input values from the user and then display the values in PHP using the same page. The code is very simple and easy to understand ideal for beginners in PHP programming.
If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. 
My mobile number here in the Philippines is 09173084360.
// By: Jake R. Pomperada
//**************************************

<?php
error_reporting(0);
$fname = $_POST['fn'];
$age = $_POST['a'];
$course = $_POST['crs'];
 
 
 if ($_POST['clear'])
{
 $fname="";
 $age="";
 $course="";
 $message1="";
 $message2="";
}
 if ($_POST['send']) 
 {
$message1 = "Hello " .$fname;
$message2 = "Your are $age years old and your course is $course.";
	}
?>
<html>
 <style>
 body {
 font-family:arial;
 font-size:12;
 }
</style>
<title> BUILT IN FUNCTIONS</title>
<form action = "" method = "POST">
<body>
<table border = 3>
<tr>
<td> Name: </td>
<td> <input type = text name = fn value = "<?php echo $fname;?>" size="50" autofocus>
</tr>
<tr>
<td> Age: </td>
<td> <input type = text name = a value = "<?php echo $age;?>" size="3">
</tr>
<tr>
<td> Course: </td>
<td> <input type = text name = crs value = "<?php echo $course;?>" size="50" >
</tr>
<tr>
<td colspan = 3>
<input type = "submit" name="send" value = "Ok" title="Click here to display values.">
<input type = "submit" name="clear" value = "Clear" title="Click here to clear text boxes.">
</td>
</tr>
</table>
</form>
 <?php
 echo "<br><br>";
echo "<font face='arial' size='4'>";
echo $message1;
echo "<br>";
echo $message2;
echo "</font>";
 ?>	 
</body>
</html>


Other 46 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.