PHP with HTML Forms

PHP with HTML Form

In this php tutorial we will learn how to write php server side code with html form to create a web page.

We already know that the html language is used to make a design of webpage.
we can design a webpage with html controls like button control, textbox control, radio button etc.

The html code design only the static web site. if we want make it dynamic then we need to do some server side programming.
Here we use php server side code with html page, we must use FORM tags for interact the page with users.

The basic html page with button control and textbox control like :

<title>My First HTML web page</title>

<FORM name="form1" action="" method="">

Name : <input type="text" name="name"><br>
Password : <input type="text" name="city"><br>
<input type="submit" name="Submit1" value="Login">



Now save above file with name firstexample.php in php script folder. here the firstexample.php is a name of our webpage.The page with two textboxes and a submit button control. when we run the firstexample.php page it would look like below screen.

PHP with HTML forms
PHP with HTML forms

Now up to this we have created simple php web page which is work as login form. Here user can enter their username and password, we need to match entered data with our user list if match then allow user to enter website. but before doing this server side coding we must to understand about the HTML attributes METHOD, ACTION and SUBMIT.

lets understand about METHOD attribute.

The html METHOD attribute

In above php example we write METHOD=”” in FORM tags.

<FORM name=”form1″ action=”” method=””>

The METHOD attribute define how the data or information should be sent to the web server. In PHP there are main two methods used to send data to web server the POST method and GET method.
Both GET and POST methods are used to send data to web server, but there are different in way to send information.

we will understand both GET and POST methods in next php tutorial in detail.

Leave a Reply

Your email address will not be published. Required fields are marked *