• My PHP Pages

    This is a complete and free PHP programming course for beginners. Everything you need to get started is set out in section one below.

Jun 21, 2013

Posted by Unknown
3 comments | 9:43 AM


Today we talk about how to work with forms in PHP.. lets make a simple form using HTML



<html>
<head>
<title>my form</title>
</head>
<body>
<form name="myform" action="" method="post">
<lable> Enter Your Name : </lable>
<input type="text" name="name"/>
<input type="submit" name="submit_btn" value="Hit on me !"/>
</form>
<!-- PHP Part begins after this line -->



Note- There is a two very impotent attributes in form tag


  • Action attribute
This action attributes use for set where to send data once form is submitted. if we keep action attribute blank it will send form data to self page or if we use some page name it will send form data to that page.


  • Method attribute
There is two method attribute values that we can use one is 'post' other once is 'get'. both methods are use to send data but they uses different methods. if we use 'post' method it will send data using HTTP port translation or if we use get method it will send data using URL variables



How to catch submitted data using PHP

There is two methods to catch data as well. if we use 'post' method to send data we have to use $_POST array to catch data or if we use 'get' method to send data we have to use $_GET array here.

I used 'post' method before so i will use $_POST array here..

<?php

if(isset($_POST['submit_btn']))
{
$name = $_POST['name'];
echo "Your Name is :". $name;
}
?>

Note : isset() method is use for identify that variable is set and is not null



Completed Code..

<html>
<head>
<title>my form</title>
</head>
<body>
<form name="myform" action="" method="post">
<lable> Enter Your Name : </lable>
<input type="text" name="name"/>
<input type="submit" name="submit_btn" value="Hit on me !"/>
</form>

<!-- PHP Part begins after this line -->
<?php

if(isset($_POST['submit_btn']))
{
$name = $_POST['name'];
echo "Your Name is :". $name;
}
?>
<!-- PHP part ends -->

</body>
</html>

Note : If we use a value for action attribute we have to place the php code in relevent php page that we use as action attribute value. as a example if you set your action attribute value as action="process.php" you have to place your php code inside process.php file..






3 comments :

  1. PHP gana me vidiyata site ekak haduwata godak thanks machan ... me site eka navaththanna balagena hadanna epa ..... PHP vala Basic vagema PHP vala Advance deval godak idiriyedi sadahan karanna kiyala illanava .... mokada PHP kiyanne programming karana ayata vagema web design karana ayatath godak vadagath language ekak nisa.

    ReplyDelete