Home of web learners

www.webn3rd.com

PHP form is used to get input from user

PHP can work with html,as you seen a registration form or login form by using html,so how to take those data,user input in fomr.

Let's start

Start with a html form

<form action="submit.php" method="get">
<input type="text" name="userdata">
<input type="submit"/>
</form>

save this code file as as form.php

your html form is ready,now get data from form to php

Look previous form example here you see in

That means when you click submit button in form browser goes to new page named submit.php

Another attribute in form which is method used to type of method for data sending,for here,we use get method so you can see data which you give input to form can see in brwoser url

We also use here name attribute in input which is used to identify which input data

Now you have to write php code to grab form input data

Look below example:

<?php
$a=$_GET["userdata"];
echo $a;
?>

save this code as submit.php file name,as we mention action is submit.php

Now in the above code,you see we use GET as our form data method is get,so inside this we use the name which we used in our html form name for input field,this need to be same

We take this data and assign it to a variable named $a,then we just show the variable data which is the data we gave in form

webn3rd.com

About webn3rd