Jump to content

registration check username


MDanz

Recommended Posts

i'd like to check if the username is taken. ........if it is it echo's " bla bla choose another name" and also for email, so no duplicate email for users.  how do i do this?

 

 

here's the part of the code thats relevant


     echo "<h1>Register</h1>";
         
         $submit = $_POST['submit'];
         
         $fullname = strip_tags($_POST['fullname']);
         $username = strip_tags($_POST['username']);
         $password = strip_tags($_POST['password']);
         $email = $_POST['email'];
         $confirmpassword = strip_tags($_POST['confirmpassword']);
         $date = date("Y-m-d");

         if($submit)
         {
           
           //check fields are filled
           
           if($fullname&&$username&&$password&&$confirmpassword)
           {

              
              if ($password==$confirmpassword)
              {
               //check character length of username and fullname
               
               if(strlen($username)>25||strlen($fullname)>25)

               {
                echo" Length of username or fullname is too long";
               }

               else {
                //check password length
                
                if(strlen($password)>25||strlen($password)<6)
                {
                  echo "Password must be between 6 and 25 characters";
                }
                else
                {
                 //register the user
                 //encryt password
              $password = md5($password);
              $confirmpassword = md5($confirmpassword);
              
              //open database
              
              $connect =mysql_connect("localhost","Master","password");
              mysql_select_db("Login");  //select database
                //generate random number for activation process
                
                $random = rand(23456789,98765432);
              $queryreg = mysql_query("  
              INSERT INTO Users VALUES ('','$fullname','$username','$password','$email','$date','$random','0','')
                                           ");
              $lastid = mysql_insert_id();


             

Link to comment
Share on other sites

This is going to be psuedo code, so you'll need to adapt it a bit

 

As far as mailing, take a look at this: http://us3.php.net/manual/en/function.mail.php

 


              $connect =mysql_connect("localhost","Master","password");
              mysql_select_db("Login");  //select database
                //generate random number for activation process

              $sql = "SELECT * FROM `Users` WHERE user='$fullname'";
	$result = mysql_query($sql) or die(mysql_error());
	if (mysql_fetch_row($result) > 0)
	{
		echo "Username in use, please select another";
	}
	else
	{
                	$random = rand(23456789,98765432);
                $queryreg = mysql_query(" 
        	        INSERT INTO Users VALUES ('','$fullname','$username','$password','$email','$date','$random','0','')
                                           ");
                	$lastid = mysql_insert_id();
	}

Link to comment
Share on other sites

use mysql_num_rows to check whether email or username has been taken by other users

 

$username=$_POST['username'];

$query="SELECT * FROM yourdatabasetable WHERE usernamecolumn='$username";

 

connect this query and use mysql_num_rows

 

$count = mysql_num_rows($query)

if($count==1){echo "Username has been used";}else{

you can insert it into your database

 

hope it could help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.