. . . Refresh your Business



Have a Safe and Happy Halloween !
Symsys Info / Blog / Review Area
Location: HOME | INFORM |
Author:  Hollow

Comments (0)



This tutorial continues on from PHP 101 - How to write a quick PHP script. If you didn’t read it, or don’t want to read it, that’s fine, so long as you understand it. This tutorial will give you all the code you need to continue from here anyway, but it will not re-explain the elements of that tutorial.

This is still a very basic how to, it expects that you (The Reader) has a server of some kind or some shared hosting which supports PHP and is already configured. The script I am about to show you will explain how to use PHP to handle an html form submission and process the output accordingly.

So let’s get going

We’re going to start by creating our html form, now this isn’t an html tutorial so we assume if you’re trying out PHP you already know html to at least a standard of understanding the code.

<label>Enter your name here : </label>
<input id="name" name="name" type="text" />
<label>Enter your Age : </label>
<input id="age" name="age" type="text" />
<input id="submit_button" style="visibility: visible" title="Submit" type="submit" value="Submit" />
 
";
?&gt;

The above code should print a nice and simple form for us, with two input text boxes and a submit button. Take the code above, save it to a file, call it PHP102.php and upload it to your web server. Then check it out and compare it to ours to see if it looks the same. If it does we can move on to the next stage, if it doesn’t you may have issues with your PHP installation or configuration.

We’re going to take PHP101.php now and change it around a little, to handle the input from our PHP102.php form. Take a look at the script below, then paste it into a text document and save it as PHP101-102.php.

The result of the above instruction should result in you getting a PHP generated, HTML form, when you go to PHP102.php, which when submitted, posts similar output to PHP101.php, but with completely different outputs dependent entirely on what information you put into the PHP102.php form.

So in this tutorial we learned how to handle a basic form submission and print the output to a page using PHP. It didn’t do anything spectacular, it isn’t a revolutionary tutorial and there are hundreds if not thousands more like it out there on the web, but hopefully you found it useful. If the first two tutorials get any comments requesting it, I’ll do a third tutorial that’s more in depth and handles the validation of a form submission and if that’s popular I’ll go further into extended validation etc and possibly MySQL usage.

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 Ltd, 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: Code, PHP... Comments (0)

Tags: , , , , , , , , , , , , , ,




Author:  Hollow

Comments (0)



Ok so I promised to write some how to’s in this blog. We have some xhtml and css how-tos and I thought it was time I wrote one for PHP.

This is a very basic how to, it expects that you (The Reader) has a server of some kind or some shared hosting which supports PHP and is already configured. The script I am about to show you will explain the very basic principles of using a PHP script to process information. In later how-tos I will show how to take this knowledge and use the PHP script you generate here, to interpret input from a web form and process an output.

So let’s get going

The first thing you need to do is start and end your PHP script, and add some comments to help you remember what you’ve done and help other coders understand what you’ve done if you need help later in your project, we do this with the tags as follows.

I feel somewhat of a sell out using the “Hello World example”, but writing this how to I suddenly realize why all the others use it, simplicity. Instead of using the “Hello World example” I’m going to use something similar, it does the same thing, but just doesn’t say “Hello World”

So now we move on to using some variables. Now if you’re used to programming in other languages, it can be a good idea to forget how variables work in those languages when dealing with PHP. In PHP you don’t need to pre-define a variable, you can just create one in the middle of the script, WITH the command you intend to use it with. You also do not need to define the TYPE of variable you want it to be (i.e. as an integer, varchar, decimal, float etc, if you don’t know what this is then don’t worry, it’s just a note for programmers who haven’t used PHP before). PHP is actually intelligent enough to work this out on it’s own, dependent on what you assign to the variable. You can even then change what type of variable it needs to be later on in your script by assigning it a different variable should you so choose.

So now we’ve set our variables we can move on to doing something with them. Use the rest of the script below and upload it to your web server to see if it works. It should look like this - PHP101 Script

This isn’t the most beautiful script in the world, it isn’t the most functional, nor will it be the most helpful on it’s own, however the tutorial ‘PHP 102 - How to handle a form submission in PHP’ will be slightly more informative. We need to get PHP 101 right first however, in order that it all makes sense later.

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 Ltd, 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: Code, PHP... Comments (0)

Tags: , , , , , , , , , , , ,