Now that we have our form, we will
use this form to connect to mysql and insert to the database.
Using PHP to connect to mysql,
we can arrest the form data simply and cleanly.
For the purpose of the this tutorial, we will assume that you already have
a database created.
<form action="action.php3" method="GET">
Your name: <input type=text name=name>
You age: <input type=text name=age>
<input type=submit>
</form>
Using the code above, a form would
appear in your browser that looks like this:
Your name
Your age
There is nothing special about this
form either . It is a straight HTML form with no special tags of any kind.
When the user fills in this form and hits the submit button, the action.php3
page is called. This is where we will make the connection to the database:
What we have done is use several
commands in PHP to do 2 basic things : 1) connect to the database 2) insert
into database.
To break the commands down a little
further : <? PHP (opens the php statement)
mysql_connect (hostname *this is usually localhost*,
username * your mysql username*, password
*your mysql password*);
*; always ends a statement*
mysql_select_db *selects the database to
use* (databasename);
mysql_query (This is
your sql statement. For a tutorial on sql please see Mysql.com)