form - how to create and use form in php

form - how to create and use form in php


form.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>form - how to create and use form in php</title>
</head>

<body>
    <h2 style="color:HotPink; font-style:italic">php example: using form in php</h2>
    <hr width="350" align="left" color="Pink" />
 <br />

<table cellpadding="3" cellspacing="3" style="color:Snow; background-color:OliveDrab;">
 <form name="UserForm" action="userformaction.php" method="post">
 <tr>
     <td colspan="2" height="25">
        </td>
    </tr>
 <tr>
     <td>Your Name</td>
     <td><input type="text" name="UserName" /></td>
    </tr>
 <tr>
     <td>City</td>
     <td><input type="text" name="UserCity" /></td>
    </tr>
 <tr>
     <td colspan="2" align="right">
         <input type="submit" name="UserSubmitButton" value="Submit User Info" style="height:45px; color:OliveDrab;" />
        </td>
    </tr>
    </form>
</table>

</body>
</html>


userformaction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>how to use form in php</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">php example: using form in php</h2>
    <hr width="325" align="left" color="Orange" />
 <br />
    
<?php 
 echo "<div style='Background-color:Snow;width:450px;color:Green;font-size:large'>";
  echo "Submitted user name: ";
  echo $_POST["UserName"];
  echo "<br />";
  echo "Submitted user city: ";
  echo $_POST["UserCity"];
 echo "</div>";
?>

</body>
</html>