Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • FORM HANDLING IN PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 169
    Comment on it

    Below is a  simple html form which have two input type fields and submit button :-

    <html>
    <body>
    
    <form action="form_post.php" method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>
    
    </body>
    </html> 

    When we fill all these fields and submit it by clicking on submit button, then the form data is sent for processing to a file which contain php code, name form_post.php. Here we were sending the form data with the help of POST method.

    For seeing data which we enter in input fields we can simply echo or print all the variables in form_post.php file.

    form_post.php look like this :-

    <html>
    <body>
    
    Your name is <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; 
    ?>
    
    </body>
    </html> 

     

    OUTPUT

    If we enter suresh in name field and suresh.ramola123@gmail.com in email field than following output comes.

    Your name is suresh
    Your email address is suresh.ramola123@gmail.com

    We can also get this same result by using GET method.

    <html>
    <body>
    
    <form action="form_get.php" method="get">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>
    
    </body>
    </html>

     We are sending above form with the help of GET method

    form_get.php looks like this:-

    <html>
    <body>
    
    Your name is <?php echo $_GET["name"]; ?><br>
    Your email address is: <?php echo $_GET["email"]; 
    ?>
    
    </body>
    </html> 

    This will also give the same output:-

    Your name is suresh
    Your email address is suresh.ramola123@gmail.com



     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: