Search code examples
phpformssuperglobals

What is the purpose of $_POST?


I know it is php global variable but I'm not sure, what it do? I also read from official php site, but did not understand.


Solution

  • You may want to read up on the basics of PHP. Try reading some starter tutorials.

    $_POST is a variable used to grab data sent through a web form.

    Here's a simple page describing $_POST and how to use it from W3Schools: PHP $_POST Function

    Basically:

    Use HTML like this on your first page:

    <form action="submit.php" method="post">
      Email: <input type="text" name="emailaddress" /> <input type="submit" value="Subscribe" />
    </form>
    

    Then on submit.php use something like this:

    <?
      echo "You subscribed with the email address:";
      echo $_POST['emailaddress'];
    ?>