Tutorial for $_POST in Super Global Variables

What is $_POST?

It’s a global variable that’s used to collect data from the HTML form after it’s been submitted. Because the data is not accessible in the query string when a form uses method post to transfer data, security standards are maintained in this manner.

Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to the file itself in this case. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_POST:

Output:-

Before filling Data.
Just filling some data
After clicking on Submit button

We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables. We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables.

Tagged : / / / / / / / / / /

Tutorial for $_REQUEST in Super Global Variables

What is $_REQUEST?

$_REQUEST is a super global variable that’s used to collect data when an HTML form is submitted. Because $_POST and $_GET accomplish the same purpose and are extensively used, $_REQUEST is rarely used.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to this file in our example. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_REQUEST:

Output:-

Empty box
Just fill some data
After Clicking on submit button it shows this result

We’ve constructed a form in the above code that accepts the user’s name as input and prints it when the submit button is pressed. Because we alter the data on the same page using PHP code, we transfer the data received in the form to the same page using the $_SERVER[‘PHP SELF’] element as stated in the action attribute. The $_REQUEST super global array variable is used to obtain the data.

Tagged : / / / / / / / / / /

Tutorial for $_SERVER in Super Global Variables

What is $_SERVER?

It’s a super global variable in PHP that keeps track of headers, paths, and script locations. Some of these components are used to obtain data from the $_SERVER super global variables.

Server IP (PHP $_SERVER variables) | Drupal.org

Example:-

Output:-

To retrieve some information, we used the $_SERVER components in the code above. Using the ‘PHP SELF’ element, we retrieve the current file name that is being worked on. Then, using the ‘SERVER NAME’ attribute, we retrieve the current server name. Then we use ‘HTTP HOST’ to retrieve the host name.

The following table lists the most important elements that can go inside $_SERVER:

Element/CodeDescription
$_SERVER[‘PHP_SELF’]Returns the filename of the currently executing script
$_SERVER[‘GATEWAY_INTERFACE’]Returns the version of the Common Gateway Interface (CGI) the server is using
$_SERVER[‘SERVER_ADDR’]Returns the IP address of the host server
$_SERVER[‘SERVER_NAME’]Returns the name of the host server (such as www.w3schools.com)
$_SERVER[‘SERVER_SOFTWARE’]Returns the server identification string (such as Apache/2.2.24)
$_SERVER[‘SERVER_PROTOCOL’]Returns the name and revision of the information protocol (such as HTTP/1.1)
$_SERVER[‘REQUEST_METHOD’]Returns the request method used to access the page (such as POST)
$_SERVER[‘REQUEST_TIME’]Returns the timestamp of the start of the request (such as 1377687496)
$_SERVER[‘QUERY_STRING’]Returns the query string if the page is accessed via a query string
$_SERVER[‘HTTP_ACCEPT’]Returns the Accept header from the current request
$_SERVER[‘HTTP_ACCEPT_CHARSET’]Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1)
$_SERVER[‘HTTP_HOST’]Returns the Host header from the current request
$_SERVER[‘HTTP_REFERER’]Returns the complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER[‘HTTPS’]Is the script queried through a secure HTTP protocol
$_SERVER[‘REMOTE_ADDR’]Returns the IP address from where the user is viewing the current page
$_SERVER[‘REMOTE_HOST’]Returns the Host name from where the user is viewing the current page
$_SERVER[‘REMOTE_PORT’]Returns the port being used on the user’s machine to communicate with the web server
$_SERVER[‘SCRIPT_FILENAME’]Returns the absolute pathname of the currently executing script
$_SERVER[‘SERVER_ADMIN’]Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as someone@w3schools.com)
$_SERVER[‘SERVER_PORT’]Returns the port on the server machine being used by the web server for communication (such as 80)
$_SERVER[‘SERVER_SIGNATURE’]Returns the server version and virtual host name which are added to server-generated pages
$_SERVER[‘PATH_TRANSLATED’]Returns the file system based path to the current script
$_SERVER[‘SCRIPT_NAME’]Returns the path of the current script
$_SERVER[‘SCRIPT_URI’]Returns the URI of the current page
Tagged : / / / / / / / / / /

Tutorial for $GLOBALS in Super Global Variables

What is $GLOBALS?

$GLOBALS is a super global variable that may be accessed from anywhere in the PHP script. All global variables are stored in the array $GLOBALS[], where index is the global variable name that may be retrieved.

All global variables are stored in an array named $GLOBALS[index] in PHP. The variable’s name is stored in the index.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

The example below shows how to use the super global variable $GLOBALS:

Example:-

Output:-

Two global variables, $x and $y, are declared in the above code and are given a value. Then, in the GLOBAL array, a function multiplication() is written to multiply the values of $x and $y and store the result in another variable $z.

Tagged : / / / / / / / / / /

Tutorial for Super Global Variables in PHP

What is Super Global Variables in PHP?

These are PHP array variables with specific definitions that make it simple to retrieve information about a request or its context. The super global variables may be found all across your script. These variables can be accessible from any function, class, or file without the need to do any further steps, such as defining a global variable. They are mostly employed in applications to save and retrieve data from one page to the next.

PHP Variables and scopes

The following are the PHP superglobal variables:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
PHP 5 Global Variables - Superglobals - MEGATEK ICT ACADEMY
Tagged : / / / / / / /

Tutorial for Method Attribute in html for php

What is Method Attribute?

The HTTP method used to transfer data while submitting the form is specified using the HTML form> method Attribute. The HTTP methods GET and POST are the two types of HTTP methods. With the form> element, the method attribute can be used.

Html 4

Attribute Values:

  • GET:- When using the GET method, the form data are shown in the address bar of the new browser tab once the form is submitted. It is restricted to around 3000 characters in length. It’s just good for non-sensitive data, not for sensitive data.
  • POST:– After submitting a form with the post method, the form values will not appear in the address bar of the new browser tab, as they did with the GET method. The form data is appended to the body of the HTTP request. It is unrestricted in terms of size. The outcome of this technique is not bookmarkable.

Which are the Supported Tags:

<form>

Syntax:

<form method="get|post">

Example 1:– This example illustrates the use of GET method attribute.

Output:-

Example 2: This example illustrates the use of the POST method attribute. This method sends the form-data as an HTTP post-transaction. 

Output:-

Tagged : / / / / / / / / /

Tutorial for Enctype Attribute in html for php

What is  Enctype Attribute?

This Attribute indicates that data in the form should be encoded before being submitted to the server. This sort of property can only be utilised if the method is set to “POST.”

Syntax:

<form enctype = "value">

Element:– The enctype property is only applicable to the form> element.

Attribute Value: There are three values for this characteristic, which are given below:

  • application/x-www-form-urlencoded:– It’s the default setting. Before sending the data to the server, it encodes all of the characters. Spaces are converted to + symbols, while special characters are converted to their hex value.
  • multipart/form-data:– There is no character encoded in this value.
  • text/plain:– This value converts spaces to + symbols, however it does not convert special characters.

Example:

Output:-

Supported Browsers: The browser supported by enctype Attribute are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Apple Safari

Tagged : / / / / / / /

Tutorial for Action Attribute in html used in php

What is Action Attribute?

It contains a URL that defines where to send the data after submitting the form.

It specifies the physical address of the server to which the user data should be redirected at the click of the submit button.

The action property specifies what should happen when the form is submitted.

When a user presses the submit button, the form data is usually transferred to a server file.

The form data is delivered to a file called “action page.php” in the example below. This file includes a server-side script for dealing with form data:

Example:-

Output:-

Tagged : / / / / / /

Tutorial for Type Attribute in php

What is Type Attribute?

It indicates the type of input element. It’s an empty tag. The default value is text.

Example:-

<input>

<input type=“text”>
  • Text – It defines a single-line text field.
<input type=“text”>
  • Password – A password field is like text field, the difference being that this control hides each typed character by displaying an asterisk(*) or bullets(●) instead of the character itself.
<input type=“password”>
  • Button – This is used to add a button on a web form to activate a script when an user click the button.
<input type=“button”>
  • Email – This field is used to add an email address or a list of email address to a form, where type=“email” is a value for the input type. The input format should be an email like example@gmail.com else it will prompt an error.
<input type=“email”>
  • Check Box – A check box is a small box, which when selected includes a checkmark. It is used to allow the user to select one or more than one of the options available on a web page. An User can select or clear the check box by clicking it
<input type=“checkbox”>
  • Radio Button – A radio button is used to create a series of options of which only one can be selected. It is displayed as a circle which when selected, displays a dot in the middle.
<input type=“radio”>
  • URL – The URL field is used to enter only the web addresses, in their correct format. If the URL is not entered in the correct format then the URL field validates the text field to enter web address.
<input type=“url”> 
  • Autofocus – helps in keeping the focus of mouse pointer on the input field.
  • Pattern – defines the regular expression of the text that should be entered in the text field.
  • Search Box – This is used to add a search box to a form.
<input type=“search”>
  • Tel – The tel type represents a one-line plain-text edit for entering a telephone number.
<input type=“tel”>
  • Range – Range input represents the input of limited range numerical values.
<input type=“range”>
  • Number – Number is used to validate the textbox only if the value within the field is a numerical value.
<input type=“number”>
  • File – This is used to upload a file on a web page. You also need to set the enctype=“multipart/form-data”
<input type=“file”>
  • Image – It represents either an image from which the UA enables a user to interactively select a pair of coordinates and submit the form, or alternatively a button from which the user can submit the form.
<input type=“image”>
  • Hidden – A hidden control stores the data that is not visible to the user on a web page. This control is used to submit some information, which can not be edited by user.
<input type=“hidden”>
  • Submit – A submit button is used to transfer form data to the URL specified in the <form action> tag.
<input type=“submit”>
  • Reset Button – A reset button helps user to clear all the data that they have entered in the text fields.
<input type=“reset”>

  • Date – This is used for input fields that should contain a date.
<input type=“date”>
  • Time – It allows the user to select a time.
<input type=“time”>
  • DateTime – It allows the user to select  date and time.
<input type=“datetime”>
  • Datetime-local – It allows the user to select a date and time.
<input type=“datetime-local”>
  • Month – It allows the user to select a month and year.
<input type=“month”>
  • Week – It allows the user to select a week and year.
<input type=“week”>
  • Color – It is used for input fields that should contain a color.
<input type=“color”>
Tagged : / / / / / /

What are the Tags used to create Forms?

What are the Tags used to create Forms?

HTML forms are used to collect some data from the site visitor. The HTML <form>…..</form> tag is used to create an HTML form

<input>
<textarea>
<button>
<select>
<option>
<optgroup>
<fieldset>
<label>

Why Input Tag is used?

<input> tag prompts the user to enter data and also request for the information from the web server after submitting the web form.

How it is Used?

<form>
	<input>
</form>
Tagged : / / / / / / / /