One of the main things that really makes people confused is forms when first learning PHP. Hopefully this tutorial will help clear some of that stuff up.
Creating the HTML Form
First of all you need to create a form on aseparatepage to the one which will be handling the form. You could call this form.html. In form.html insert the following contents:
<form action="process.php" method="POST">
<p>Name: <input type="text" name="name" />
</form>
First of all you are initialising the form telling it to 'POST' the contents of the form (name) to the action page (process.php).
Creating the PHP Page
Now create a file called process.php and insert the following contents:
<?php
print "Hello " . $_POST["name"];
?>;
This code basically handles the POST data that was sent to it and prints the value out onto the webpage. Of course you don't have to print it. You could put it in a variable for later use on the webpage:
<?php
$name = $_POST["name"];
?>;
However, do be warned that anyone can post data to your process page - so please make sure you use mysql_escape_string PHP function to prevent SQL Injection.
This should help you with basic PHP Form Submission - I will be creating another tutorial to detail how to use forms to upload files - which can be fairly complex.
Copyright PHPTutorials.co © 2009 - 2010