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
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..
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.
ReplyDeleteaniwa kollo
ReplyDeletehttps://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
E1E1