PHP Form POST and GET Tutorial

Creator:
Michael4

This tutorial will learn you the POST and GET method's of form's GET Method The GET method is an alternative to the POST method. If we were to change the method to GET, it would look like this

<form action="page.php" method="get"> Test: <input type="text" name="text"><br/>
Test:
<input type="text" name="textt"><br/>
<input type="submit" name="submit"
value="Submit"></form>

The GET method is different to the POST method, the GET method passes the variables to along to the page.php by appending the variables to the end of the page.php URL. The URL would look like this page.php?text=value&textt=value. The question mark tells the browser that the following items are variables. Now that we have changed the form method to GET, we need to set the variables like this

$item = $_GET['text']; $itemt = $_GET['textt'];

Using the GET method, the code will show the variables to the user, so be sure you are not sending passwords or any other sensitive information with the GET method. POST Method

<form action="page.php" method="post"> Test: <input type="text" name="text"><br/>
Test:
<input type="text" name="textt"><br/>
<input type="submit" name="submit"
value="Submit">
</form>

This code will send the data to page.php using the POST method. The way PHP does this is to store the data into an array $_POST. Be sure to take note of the input names, as they will represent the keys in the $_POST array. We need to set the variables $text = $_POST['text']; $textd = $_POST['textt']; The form names are used as the keys in $_POST, so be sure you don't have two input forms with the same name. Thank you for reading my PHP Form POST and Get tutorial. Thank you Michael

Description:
This tutorial will learn you the POST and GET method

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options