Free web development scripts for the webmasterDevelopment Scripts


 
 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o PHP
   o Online Communities
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o White Watch Store
 o iPad 64gb 3g
 o Free Wedding Websites
 o Invoice Software
 o UK Business Franchises
 o OxyScripts
 o Invoice Software

Add a Member to a Users Database (Rated 5)

Description:

This is a simple example of how you can add users to a database to allow them to register to see various area's of your site.

I suggest having some javascript client side validation of the text fields, along with server side validation in case people don't have java turned on.

Code starts here


// SQL to create the Users Table
CREATE TABLE users (
UserID int(11) NOT NULL auto_increment,
UserName text NOT NULL,
Password text NOT NULL,
PRIMARY KEY (UserID)
) TYPE=MyISAM;

// Registration form.html
<form id="registration" name="registration" method="POST" action="register.php">
<table width="100%" border="0" align="center" cellpadding="8" cellspacing="0">
<tr>
<td><div class="small" align="right">Username *</div></td>
<td><input name="username" type="text" size="30" maxlength="35" /></td>
</tr>
<tr>
<td><div class="small" align="right">Password *</div></td>
<td><input name="password" type="password" size="30" maxlength="35" /></td>
</tr>
<tr>
<td><div class="small" align="right">* denotes <strong>required</strong> fields</div></td>
<td>
<input type="submit" name="submit" value="Register" onclick="" />
</td>
</tr>
</table>
</form>

// register.php
<?PHP
include_once('form.html');

if(isset(
$_POST['submit']))
{
$username = strip_tags($_POST['username']) ;
$password = md5($_POST['password']);

// Connect to your database here...

//Check details not already in database..
$q1 = "SELECT COUNT(*) FROM `users` WHERE `UserName` = '$username'";
$res = mysql_query($q1);
$res = mysql_fetch_array($res);

if (
$res[0] == 0)
{
// Users is a simple table with UserID (auto inc), password and username.

$query = "INSERT INTO `users` (`UserID`, `Password`, `UserName`) VALUES ('','$password', '$username')";
$result = mysql_query($query) or die ("Error executing " . $query . " - " . mysql_error());
}
else
{
// Username or email address already in use
// Handle this how you want
}
}
?>

Last Edited: March 20, 2003, 12:37 pm


Submitted by Devscripts on 20-03-2003 12:37


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net