Many sites today require implementing user registration and functions. Whether you’re upgrading an existing site to incorporate a mySQL database, or want to better understand how to incorporate user features from scratch, this guide is for you. PHP and mySQL work hand in hand when it comes to user features – you can sync the entire registration, update and retrieval process through a centralized form. Adding user functionality can help you customize the site for users, add profiles and other special features.
At a basic level, user registration only require a single mySQL table, although most sites will implement a variety of rich features to customize based upon user preferences. Large sites such as Facebook rely upon expansive user databases in order to properly implement new settings. While they have extensive networked servers, specialized programming and complex cache procedures, you can begin building up your own user-driven site with some basic programming.
To begin, you’ll need to create a user table within mySQL. You can do this directly from shell or you can use a tool such as PHPmyAdmin or another database program. Make sure you fully understand what you’re doing in the process, since you’ll be required to make updates to the table in the future. To start, you’ll create a table that provides the basic elements of user registration – note that you can adjust these fields according to your registration requirements:
CREATE TABLE 'Site_Users'.'users' ( 'number' INT AUTO_INCREMENT , 'user' VARCHAR( 40 ), 'pw' VARCHAR( 25 ) , 'email' VARCHAR( 30 ) , 'postal_code' VARCHAR( 5 ) , )
Using these basic commands we created our site users database to capture their username, password, email address and zip code. You can easily add other features such as user type, membership type or other preferences. Some of these can also be added later to allow users to upgrade their subscriptions or to customize your site. Keep in mind you’ll want to consider whether to treat international users (who have different postal codes) in the same table.
In order to properly implement a registration form, you’ll first need to build a PHP script to connect to the database. With a flexible script you’ll be able to utilize a wide variety of functions to capture logins, registrations, echo user names or preferences, as well as customizing the site based upon user ideas. As your core PHP file you’ll be required to connect to the database and query the right row so you can identify the user. It’s necessary to build out this file in advance of implementing an actual javascript or HTML registration form. Keep in mind the following parameters when you build out your PHP scripts:
function user_login ($user, $pw) {
$username = mysql_real_escape_string($user);
$sql = "SELECT * FROM users WHERE username = user AND password = ‘pw’;";
$result = mysql_qury($sql);
}
There are a variety of ways to check for duplicate registration or proper logins, but the most effective is probably to determine whether the row already exists. Users should be required to user unique usernames, so that there are no duplications in your table. With a properly defined user structure, you will be well on your way to building a social site.
1. Response by : Siraj Darvesh on Mar 6, 2011 at 4:57 pm
This is really good, although I would be more interested in someone who can help me do the coding based on my database needs. It will be web based and I am very confident it will become a large user database, bigger that FB and twitter. I know its a big claim but I have to start somewhere!
Im currently finishing a presentation for funding to a bank via an accountant. I was thinking that since you have written this article you may know an excellent database builder?
Thank you for this article it was once again really good.
| 1 | Hostpapa - £ 1.95 |
| 2 | UK2NET - £ 3.95 |
| 3 | Clook - £ 5.00 |
| 4 | WebHosting.uk.com - £2.29 |
| 5 | Just Host - £3.45 |
| 6 | 1and1 - £ 2.49 |
| 7 | Webfusion - £3.95 |
| 8 | FastVision - £1.49 |
| 9 | Heart Internet - £2.49 |
| 10 | FastHosts - £ 3.49 |