A Blog about Linux, Open Source and Code! 
Symsys Inform Blog Home

Symsys Ltd Text logo in the banner area





 

 

I’ve decided to re-write my PHP How To’s. This is the first, it doesn’t actually include any PHP, instead this tutorial simply shows you how to setup a basic HTML form with two input boxes and a button, the tutorial following this one will explain how to write a php script that will receive the details from this form, process them and then do something with the result.

This tutorial assumes that you already have a relatively in depth knowledge of HTML and how it works, if you don’t then stop reading now, go and learn a little HTML first, before you try starting with PHP, if you don’t understand the supporting language of HTML then you will not understand what the PHP is doing. I also assume that you have some form of a test server, be it a server or shared hosting that supports php, you must have some way of testing your PHP code for this tutorial to work, if you don’t have one, get one. I will try to write a tutorial on installing a basic LAMP (Linux Apache MySQL PHP) server at some point in the future and link to it here, but as yet I have not written one.

So after declaring our HTML DTD and putting in our standard html, head and body tags, we need to start writing our form. We are going to use label tags here because in a later tutorial I’ll show you how to use them to properly space out your form using CSS and of course we are using input tags for our text boxes and submit buttons. The most important attributes of these input tags are the “name” tags, these are the identifier tags, which will get passed across to our PHP script in the next tutorial via the POST method.

Once you’ve got your form laid out the way the code shows above (Yes at this point you can copy n paste a little, but beware you need to understand what you’re copying and pasting or the other tutorials may not work properly and you may not benefit from them) you should be able to upload it and see a basic HTML form in your web browser.

Save the file as something simple like “my-first-form.php”, save it as a .php file, this way we can test that the PHP engine is running first and foremost but later we are going to do error handling and that will require the form to be a php document. It’s not pretty right now and it’s nothing special, but it’ll work for what we want.

Your form should have a textbox to enter a name, another to enter your age and a simple submit button. If your form does not show the way I’ve described, then something has gone wrong and you should start again or you may need to look at your server setup if the page does not display at all. If your form displays correctly then all is well and you can move on to PHP Tutorial 1.1 – Processing simple form input using PHP and the POST method.

The code in this tutorial is under no license whatsoever and is completely free to be re-used by anyone and for any purpose. No warranty of guarantee is provided with this code and it is used, re-used, re-distributed or sold at the persons own risk. In no way is Symsys, or the author of the tutorial, responsible in any way, for the way this code is used by a third party or how it may be developed by that third party. Please use any and all code here responsibly.


Filed under: PHP ... Comments (4)


  

 





4 Responses for "PHP Tutorial 1.0 – How to write an html form using post"»

  1. john doe

    i’m leaving a message

  2. Hollow

    And I’m leaving a reply.

  3. Hollow

    Good for you, sometimes I wish I could.


Leave a Reply

468x60-1

Enter your email address:

Delivered by FeedBurner