Create a simple HTML form with 2 input fields and one submit button.

<form action=”test.php” method=”post”>

<tr>

<td>

First Name:

</td>

<td>

<input name=”firstname” id=”firstname”/>

</td>

</tr>

<tr>

<td>

Last Name:

</td>

<td>

<input name=”lastname” id=”lastname”/>

</td>

</tr>

<tr>

<td>

<input type=”submit” name=”submit” value=”Submit Form”/>

</td>

</tr>

</form>

Create 2 local variables to store the values entered by user.

$firstname=””;

$lastname=””;

$firstname=$_POST[‘firstname’];

$lastname=$_POST[‘lastname’];

Display the values entered by user..

$firstname=stripslashes($firstname);

$lastname=stripslashes($lastname);

$firstname=strip_tags($firstname);

$lastname=strip_tags($lastname);

echo “Firstname – ” . $firstname;

echo “Lastname – ” . $lastname;

Complete code is given below

<body>

<table>

<form action=”test.php” method=”post”>

<tr>

<td>

First Name:

</td>

<td>

<input name=”firstname” id=”firstname”/>

</td>

</tr>

<tr>

<td>

Last Name:

</td>

<td>

<input name=”lastname” id=”lastname”/>

</td>

</tr>

<tr>

<td>

<input type=”submit” name=”submit” value=”Submit Form”/>

</td>

</tr>

</form>

</table>

</body>

 

<?php

$firstname=””;

$lastname=””;

$firstname=$_POST[‘firstname’];

$lastname=$_POST[‘lastname’];

$firstname=stripslashes($firstname);

$lastname=stripslashes($lastname);

$firstname=strip_tags($firstname);

$lastname=strip_tags($lastname);

echo “Firstname – ” . $firstname;

echo “Lastname – ” . $lastname;

?>