Thursday, 18 June 2020

php forms

php get form
form1.html
1. <form action="welcome.php" method="get">  
2. Name: <input type="text" name="name"/>  
3. <input type="submit" value="visit"/>  
in html page , whenever it submits, it redircts to welcome.pho
4. </form>  
welcome.php
1. <?php  
2. $name=$_GET["name"];//receiving name field value in $name variable  
it gets the value
3. echo "Welcome, $name";  
it prints the value
4. ?>  
get willl show in url
php post form
form1.html
1. <form action="login.php" method="post">   
2. <table>   
3. <tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>  
post will not show in url
4. <tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>   
5. <tr><td colspan="2"><input type="submit" value="login"/>  </td></tr>  
6. </table>  
7. </form>   
login.php
1. <?php  
2. $name=$_POST["name"];//receiving name field value in $name variable  
3. $password=$_POST["password"];//receiving password field value in $password variable  
4.   
5. echo "Welcome: $name, your password is: $password";  
6. ?>  

No comments:

Post a Comment