Thursday, January 12, 2017

GET and POST variables

GET Variables: getvariables.php !
      <!doctype html>
         <html>
          <head>
            <title>My First Webpage</title>!
              <meta charset="utf-8" />
              <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
              <meta name="viewport" content="width=device-width, initial-scale=1" /> !
          </head> !
<body>
             <div>
                             <?php
                                   if ($_GET["submit"])
                                          {          
                                               if ($_GET["name"])
                                                          {  
                                                                 echo "Your name is ".$_GET['name'];
                                                           }
                             
                                                  else
                                                            {
                                                                        echo "Please enter your name";                                                                  }  
                                            }
                                   ?>
                  <form>
                             <label for="name">Name</label>
                             <input name="name" type="text" />
                            <input type="submit" name="submit" value="Submit Your Name" />
                  </form>
             </div>
</body>
</html>



POST VARIABLES
           The major difference between POST and GET variable is that, if you use GET user entered value will be displayed in url but not in case of POST. I recommend you to use POST.
Coding is same.. Just repalce GET by POST.

2 comments: