PHP Form Handling


PHP Form Handling:– When a form is submitted to a php script.the information from that form is automatically made available to the script. There are few ways to access this information which are described in below example.


PHP Form Handling | Example

Now we are going to explain below example how does a html form data is processed by a php script.Here you can see getform.php file is defined on form action tag which simply means that when user clicks on submit button then form input field values will be processed by php script using post method. Here you can also use get method instead of post method but for security reasons we never recommend to use it .

.

Example of PHP Form Handling.

<html>
<body>
<form action="getform.php" method="post">
 <p>Your name: <input type="text" name="name" /></p>
 <p>Your age: <input type="text" name="age" /></p>
 <p><input type="submit" /></p>
</form>
</body>
</html>


Description of getform.php.

<?php
echo $_POST['name'];
echo $_REQUEST['age'];
?>


OR

<?php
Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int)$_POST['age']; ?> years old.
?>



Advertisements

Add Comment

📖 Read More