2. POST
Post is a method to send data use form. Different with Get method , Post method sending confidential data, like password at login in a websit or the other. Let's see example script of Form with Post method.
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="process_post.php" method="post">
<Pre>
Name :<input type="text" name="name"/>
Address:<textarea name="address"></textarea>
</pre>
<input type="submit" value="Send">
</form>
</body>
</html>
Let's see output of script above.
To show output data when it is sent, we must create a new file which is used to display data. Below is script that file.
<?php
echo"<pre>";
print_r($_POST);
echo"</pre>";
?>
Let's see output of data after data is sent. Below is output from typing of data until showing data.
Below is data show.
different with get method, method post can not change the contents of data via addrass bar, because data which is sent is not shown on address bar.
For the display of data looks more beautiful, use the script below.
<?php
echo "Name : ".$_POST['name'];
echo "<br />";
echo "Address : ".$_POST['address'];
?>
Below is output script above after data inputted from form.
Below is brief explanation about script above.
To catch the value or data of the form, we can use the $ _POST and followed with name of element , see picture above, element <input type="text" name="name"/> has a name "name" so we can catch the name like $_POST['name'].
Read more about Form click here to elements of Form in PHP and Form HTML Part 3.
No comments:
Post a Comment