Thursday, March 26, 2015

Get user values and Display without database

Here is simple php program to get values from user and display the values without database.



# Get values from user & print in front
<?php

$name = ' ';    //by default we declare variables none
$age = '';    //by default we declare variables none
$type = '';    //by default we declare variables none
$status = '';    //by default we declare variables none
$doj = '';    //by default we declare variables none

// check if user press the submit button then follow
if(isset($_POST['submit']))
{
$name=$_POST['uname'];  // store values in variables
$age=$_POST['age'];
$type=$_POST['type'];
$status=$_POST['status'];
$doj=$_POST['doj'];
}
?>
<table width="30%" align="center" border="1px">
<tr bgcolor="#990000">
    <th style="color:#FFFFFF">Field</th><th style="color:#FFFFFF">Input Values</th>
</tr>
<tr>
<td>Name : </td><td><?php echo $name; ?></td>
</tr>
<tr>
<td>Age : </td><td><?php echo $age; ?></td>
</tr>
<tr>
<td>Type : </td><td><?php echo $type; ?></td>
</tr>
<tr>
<td>Status : </td><td><?php echo $status; ?></td>
</tr>
<tr>
<td>Date of Joining : </td><td><?php echo $doj; ?></td>
</tr>
</table>
<br />
<!-- call same page through php_self function or we can also call page through file name -->
<form action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post">
<table align="center" width="35%" border="1px">
    <tr bgcolor="#990000">
        <th style="color:#FFFFFF">Field</th><th style="color:#FFFFFF">Input Values</th>
    </tr>
<tr>
    <td>User Name</td><td><input type="text" name="uname" value="Name" /></td>
    </tr>
    <tr>
        <td>Age</td><td><input type="text" name="age" value="Age" /></td>
    </tr>
    <tr>
        <td>Type</td><td><input type="text" name="type" value="Type" /></td>
    </tr>
    <tr>
        <td>Status</td><td><input type="text" name="status" value="Status" /></td>
    </tr>
    <tr>
        <td>Date of Joining</td><td><input type="date" name="doj" value="Date of Joining" /></td>
    </tr>
    <tr>
        <td colspan="2" style="padding-left:150px;"><input type="submit" name="submit" value="Show" />&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Clear" /></td>
    </tr>
</table>
</form>

No comments:

Post a Comment