Form Handling

Rate: 1 Star Rate: 2 Stars Rate: 3 Stars Rate: 4 Stars Rate: 5 Stars

Love it / Hate it

Comments + Likes

Form Handling

Programming / PHP

Form Handling

How to handle PHP Forms
Form Handling was posted by listylister and has had 328 view(s) but has not yet been rated
Chris's Profile Picture

Posted by listylister

Their Website http://www.phptutor...

This Tutorial has had 328 Views

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.

created on 17/12/2009 @ 00:30, last updated on 30/05/2010 @ 16:00
aProject.info Twitter RSS

  Copyright PHPTutorials.co © 2009 - 2010