sign-up scripts (stopping two users having same username)

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mtbiking
-


Joined: 18 Mar 2004
Posts: 66

PostPosted: Tue Feb 15, 2005 1:47 am    Post subject: sign-up scripts (stopping two users having same username) Reply with quote

right i have a basic sign-up script but how can i get it to...


check if the username is already in use

then if not
creat the user
if so return to error page

heres my basic script

Code:

<?php
include 'includes/db.inc.php';

$username = $_POST['username'];
$password = $_POST['password'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$country = $_POST['contry'];
$tel = $_POST['tel'];
$fax = $_POST['fax'];
$mob = $_POST['mob'];
$email = $_POST['email'];
$web = $_POST['web'];

$a_user = strtoupper("$username");
$salt = substr($a_user, 0, 2);
$crypted_password = crypt($password, $salt);

mysql_connect($hostName, $userName, $passWord);

@mysql_select_db($databaseName) or die( "Unable to select database");
$query = "INSERT INTO members
            SET members_username = '$a_user',
                members_password = '$crypted_password',
                members_firstname = '$first_name',
                members_lastname = '$last_name',
                members_address1 = '$address1',
                members_address2 = '$address2',
                members_address3 = '$address3',
                members_stateprovince = '$county',
                members_zippostcode = '$postcode',
                members_country = '$country',
                members_tel = '$tel',
                members_fax = '$fax',
                members_mob = '$mob',
                members_email = '$email',
                members_web = '$web'";

@mysql_select_db($databaseName) or die( "Unable to select database");
$query2 = "INSERT INTO page
            SET page_admin = '$username'";

@mysql_select_db($databaseName) or die( "Unable to select database");
$query3 = "INSERT INTO freds
            SET fred_admin = '$username.1'";

@mysql_select_db($databaseName) or die( "Unable to select database");
$query4 = "INSERT INTO freds
            SET fred_admin = '$username.2'";

@mysql_select_db($databaseName) or die( "Unable to select database");
$query5 = "INSERT INTO freds
            SET fred_admin = '$username.3'";

@mysql_select_db($databaseName) or die( "Unable to select database");
$query6 = "INSERT INTO freds
            SET fred_admin = '$username.4'";

@mysql_select_db($databaseName) or die( "Unable to select database");
$query7 = "INSERT INTO freds
            SET fred_admin = '$username.5'";

mysql_query($query);
mysql_query($query2);
mysql_query($query3);
mysql_query($query4);
mysql_query($query5);
mysql_query($query6);
mysql_query($query7);
mysql_close();

header("Location: index.php");
?>
Back to top View user's profile Send private message
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Tue Feb 15, 2005 10:58 am    Post subject: Re: sign-up scripts (stopping two users having same username Reply with quote

insert this somewhere:
Code:

$query = "SELECT members_username FROM members WHERE members_username = '$a_user'";
//select from table "members" the field "members_username" where the value is "$a_user"

$result = mysql_query($query); //execute query
$num_rows = mysql_num_rows($result); //get the number of results returned

if( $num_rows == 0 ){
 //No results returned for the username - add the user to the db
}else
if( $num_rows >= 1 ){
 //more than one result for username found - report error
}

_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group