Thursday, November 13, 2014

Getting Data From A Request


  •  How to use the build-in $_GET array.
    • When an HTML <form> tags uses the GET method to pass data to a php page, the values is stored in a $_GET array. Beacause this array is a part of PHP, it is called build-in array.
    • Beacause this array uses the GET method, these values is passed as a part of the URL that request the pages.
      •  For example: detail.php?firstname=tien&lastname=dung.
    • To retrieve values form $_GET array, you code as following:
      • For example: $firstName=$_GET['firstname'].
  • How to use the build-in $_POST array.
    • When an HTML <form> tags uses the POST method to pass data to a php page. so passed data will be stored in $_POST array.
    • The $_POST array works like $_GET array.
    • So when should use the GET method and when should use the POST method.
      • Using GET method:
        •  when request is for a page that gets data from  a database server.
        • when request can be excuted multiple times without causing any problem.
      • Using POST method :
        • when the request that write data to a database server.
        • When excuteing the request multiple times that may cause problems.
        • When you don't want to include the parameters in URL.
        • When you want to transfer more than 4 KB of data.

No comments:

Post a Comment