Monday, April 30, 2012

PHP Introduction to Form Tutorial


Introduction to Form
The <input type="text"> tag is a text box, while <input type="submit"> creates a submit button for sending web page back to the web server.
Example: 1
index.php
<html>
    <head>
        <title></title>
    </head>
    <body>
        <form action ="loginTest.php" method="post">
            Name: <input type ="text" name="name"/>
            <input type="submit"/>
        </form>
        
    </body>
</html>
Output
Name: 
When we click submit button, nothing happens. Because in our loginTest.php is a blank or not exist yet that does not give any actions or directions or anything.

Example: 2
index.php
<html>
    <head>
       <title></title>
    </head>
    <body>
        <form action ="loginTest.php" method="post">
            Name: <input type ="text" name="name"/>
            <input type="submit"/>
        </form>
        
    </body>
</html>

loginTest.php
<html>
    <body>

<?php
   echo $_POST["name"];
?>
    </body>
</html>
Output
Name: 

Whenever we click submit button, control goes to the loginTest.php.
$_POST indicates that getting the information from a form and not a normal variable.
If you don’t write method="post", then it looks for a variable on the same page. i.e., by making $_POST, is going to look variable on another page.
echo $_POST["name"] says, we want to echo something from a form, whatever the input for the name variable.

No comments:

Post a Comment