AJAX - With PHP Variables

AJAX - With PHP Variables

Passing variables in a URL

  • In php programs, passing of variables from one page to another is performed via page URL.

Passing Variables across Pages in php :

  • URLs with variables appear as shown below :


  • What is the purpose of a question mark with id value 54?
  • The reply will indicate that it is http query string characters that are present after the question mark. A http query string holds both variables and their values. 
  • The sample given above contains http query string with a variable named "id" and the value "54".

Here is another example :


means, that the variable "name” has value as "Venkat".

Accessing the Query String Variable Inside php code :

  • Let's say you have a PHP page named people.php. Now you can call this page using the following URL :
  • With PHP, the variable 'name' can be accessed using the below code :
  • $_GET – used to access the content from named query string variable.

Multiple Query String Variables

  • Multiple ampersand separated values are passed with query string as follows :
  • The above URL’s query string accustoms two variables: name and age. Each variable is accessed via a separate $_GET as follows :
ajax get example with multiple query strings :
        <title>Query string</title>
            // The value of the variable name is found
            echo "<h1>Hello " . $_GET["name"] . "</h1>";
            // The value of the variable age is found
            echo "<h1>You are " . $_GET["age"] . " years old </h1>";
  • In the above code, assume the file name as people.php. Now two query string variables needs to be presented with data when executing this php code in the browser as