web hints
Web Design   Domains   Hosting   SEO   Traffic Generation   PPC/Advertising   Business Tips   Partners

Adding records to a MySQL database using PHP

by Amrit Hallan

PHP and MySQL -- Adding data

There comes time when your website tends to transcend the boundaries of mere brochure type looks. There is a need to interact, to seem dynamic, and to respond according to your visitor's behavior. You also want your visitors to go through a list of offerings that run into hundreds. Creating hundreds of web pages having a uniform layout for hundreds of products can become an overwhelming task. Besides, it's not easy to browse so many products sequentially -- you need a mechanism to conduct searches or create sorted indexes.

A saintly combination of PHP and MySQL can come to your rescue. Once you have created a database with a well-defined structure, you can enter records and use those records as refence.

Here you can learn how to create an SQL database and its tables.

Once you have a database ready, you need a form to accept data, and then a php file to put that data into the MySQL table.

First the form. Assume we have a file with an online form named form.html. Here's the form of the file: Once we have this form ready, we need to create the php file it calls, namely, save_it.php. Suppose the name of the database is "visitors" and the table in this database is "visinfo" with fields "name", "email" and "city".

// The above lines establishes a connection with the // database. Keep localhost as is unless something different // is mentioned by your sql host. usrnm is user name and pswd is // password. What I want to say is, copy these lines as they are // and just replace the required fields and it should connect.

$querySQL = "insert into visinfo (d_name, d_email, d_city) values ($name, $email, $city)"; if(!$querySQL) error_message(sql_error());

// The above statement generates an error if you have setup the table in such a way that there should not be a duplicate entry. ?>

In my next article(s) I'll show you how to query your database and then show the results on the web page.

Amrit Hallan is a freelance web developer. You can checkout his website at http://www.bytesworth.com. For more such articles join BYTESWORTH REACHOUT at http://www.bytesworth.com/br/default.asp or if you have a web dev related question then post it at http://www.business180.com/index.php

More Site Building articles:

12 Characteristics of a Successful Web Site
80% of Your Web Site is Maintenance
9 Near Fatal Flaws Most Links Pages Suffer From and How to Avoid Them
A Quick Web Credibility Quiz
A Quick Website Makeover Quiz
Adding records to a MySQL database using PHP
Blogs and Journalism
Create Cool Site Navigation in a Flash
Download Speed
Everybody's Talking About RSS
Free Autoresponders
How Much Should You Protect?
How Multiple Server Hosting impacts your website's uptime
How to Create and Send an HTML Email Form Using PHP
How to Get Your Visitors to Create Content for Your Website
How to Install a CGI Script and Increase Web Site Interactivity
How to Make Effective Use of Web Fonts
How To Stop Your Site Disappearing Into The Void
Images on web sites: when should they be used?
Is Your Website's Copy Up to the Mark?
Making it Tougher for Content Thieves
Six Ways to Save Your Site and the Internet
Step-by-step Guide To Building A Successful Website (Part 1)
The Most Important Question To Ask About Your Web Site!
The Pop Up Evolution. Are pop ups doomed? Or just vitally challenged?
Top 5 Must-Haves on Every Web
Unicode bloopers! HTML should not be visible on a web page!
Unix Webserver Crontab Basics
Update Your Site Instantly Using SSI
Using Tables to Format Your Web Page
Web Servers: Serving Up the Future
Websites for Search Engines or People?
What to avoid to make your website design effective?

Web Hints by Rolamtech

UK Hotels Guide  Finance Website Links  Web Hosting Guide

a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9