Skip to content

PHP Tutorial Forms and User Input

POST Method

Lesson 136 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

With method="post", the browser sends the form values inside the body of the request. They do not show up in the URL.

index.html
HTML
<form action="signup.php" method="post">
  <label for="email">Email</label>
  <input type="email" id="email" name="email">

  <label for="password">Password</label>
  <input type="password" id="password" name="password">

  <button type="submit">Create account</button>
</form>

PHP reads the values from $_POST.

index.php
PHP
<?php
$_POST = ["email" => "isha@example.com", "password" => "s3cret!"];

echo "Email: " . $_POST["email"];
Output
OUTPUT
Email: isha@example.com

(We fill $_POST by hand here so the example runs in a terminal. On a real page, PHP fills it from the form.)

Check that the form was submitted

The same file often shows the form and handles it. The request method tells them apart.

index.php
PHP
<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    // the form was submitted: process it
} else {
    // first visit: just show the form
}

You may see if (isset($_POST["submit"])) in older tutorials. It depends on the button’s name, and it fails when a form is submitted by pressing Enter in some browsers. Checking the request method is more reliable.

When to use POST

Use POST whenever the request changes something or sends private data:

  • Login and registration
  • Contact forms and comments
  • Anything that saves, deletes, buys or sends

POST data is not stored in the URL, browser history or normal server logs. It is also not magic. The visitor can still see and change it, and it is not encrypted unless the site uses HTTPS.

GET vs POST

GETPOST
Data locationURLRequest body
Visible in the URLYesNo
BookmarkableYesNo
Changes dataNo (should not)Yes
Size limitSmallLarge
PHP array$_GET$_POST

What happens on refresh

If a visitor refreshes a page that was loaded by POST, the browser asks to resubmit the form. That can send the same message twice. The fix is the Post/Redirect/Get pattern.

POST needs HTTPS

On a live site, always use HTTPS. Without it, POST data travels as plain text.

warning
Trusting hidden fields
<input type="hidden" name="price" value="100"> is still just text in the page. A visitor can change it before sending. Never accept prices, user IDs or roles from a form without checking them against your own data.