Narrow It Down ...
 Top 20 Virtual Hosts
 Top 10 Dedicated
 User Reviews
 The Help Desk !
 Community Starts...
 In the Chat Room
 
 Search for Hosting..
 Under $10 Per Month
 With ASP Support
 With PHP3/4 Support
 With Ecommerce Tools
 With WAP Support
 With JSP Support
 Dedicated Servers
control your domain


 

PHP Programming Basics - iHostcafe.com
Connecting to the database using forms -
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:
<?PHP
mysql_connect(hostname,username,password);
mysql_select_db(databasename);
mysql_query ("INSERT INTO databasename (name , age) VALUES ('$name','$age')");
echo "Got it";
?>

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)

Need More Help?Click here to try the help desk!
PREVIOUS

 Tutorials On..
 PHP and Mysql
 Ecommerce Starter
 Catch Up On..
 Webhosting News
 Ecommerce News
 General Internet
 I Can Help By..
 Adding a Review
 Submitting a Tutorial
 Writing an Article
 
Search By Price
 
 
 
 Become A Partner
 Co-Branding Programs
 Datasharing Programs
 Current Partners
 Home