Latest tutorial: Making a Movieclip face another Movieclip or point on the stage | Ask Tutorial5!
 

Build Your Own Database Driven Website Using PHP & MySQL

SitePoints Best Seller book on scripting.

  • Learn how to install and administer PHP & MySQL on Windows, Linux or Mac

  • Build your very first live Database Driven Website using PHP & MySQL

  • Instantly apply working code examples from the book to your Website


Download the free chapters now!

PHP Forms

(7 votes)
Written by DanielRo   
In our contact us script tutorial you learned the basics of creating contact forms using a PHP file and a HTML form. In this tutorial we are using only one master php file, containing both the form and the php code.



In our first tutorial we used the basic approach, a HTML FORM witch sends data using POST to a PHP file. Nonetheless this is not a bad approach in creating forms and parsing data to PHP files but as you are developing a better, stronger, faster application you will need more and more forms thus creating two files for every form can get real ugly real fast.

In this technique a single PHP file is being used, containing both the HTML FORM and the PHP script.

Here is the actual script:

<?
/*Check to see if the FORM was submitted (if the "SEND" value was sent)*/
if(isset($_POST['send']))
{
/* Get the "username" and "password" values from the form */
$user = $_POST['username'];
$pass = $_POST['password'];

/* This is the place where you connect to your database
or whatever function you are using after the form is submited */
}

/* If the "send" value was not sent, then the form is displayed */
else {
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
Username:
<input name="username" type="text"><br>
Password:
<input name="password" type="password"><br>
<input name="send" type="submit" value="Login">
</form>
<? } ?>



Subscribe now via RSS feed and get all the new tutorials

written by arun , October 18, 2007

hai this is very useful for me
written by barry manville , May 20, 2008

looking for tutorial to create a numbered sequence of forms--in this case want to offer a certificate that is sequentially numbered and where the customer can input a name.

end result would be a down loaded certificate that is numbered and has customers name on--

Do you need more help? Ask now!
 

busy
Last Updated ( Sunday, 14 October 2007 )