Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

PHP Forms

GET vs POST

{/* HTML Form */}
<form method="POST" action="process.php">
<input type="text" name="username">
<input type="submit">
</form>

Processing Form Data

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = htmlspecialchars($_POST["username"]);
echo "Hello, $name!";
}
?>

Security

  • Always sanitize user input with htmlspecialchars() or filter_var()
  • Use prepared statements for database queries
  • Validate data before processing