A php script to suggest usernames

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RPreetham
    New Member
    • Jan 2007
    • 6

    A php script to suggest usernames

    Hi,
    I am a new member.I want help in the following...
    A script that receives an username and checks if the username is
    available, if not then suggest a new username using as input
    the username, firstname , and lastname....
    Please help me.I am a beginner to PHP.
    I am no where able to find a solution to suggest name from user input firstname, middle name and last name.
    Thank you so much..
    Preetham
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by RPreetham
    Hi,
    I am a new member.I want help in the following...
    A script that receives an username and checks if the username is
    available, if not then suggest a new username using as input
    the username, firstname , and lastname....
    Please help me.I am a beginner to PHP.
    I am no where able to find a solution to suggest name from user input firstname, middle name and last name.
    Thank you so much..
    Preetham
    Are you checking against names stored in a database? Have you tried writing the script yourself? If so then please post the code you have so far.

    Comment

    • RPreetham
      New Member
      • Jan 2007
      • 6

      #3
      Originally posted by r035198x
      Are you checking against names stored in a database? Have you tried writing the script yourself? If so then please post the code you have so far.
      Below is the code which check whether the username already exist!..
      [php]
      //Check if username already exists...
      // connection to database made here
      $q2 = mysql_query("SE LECT * FROM `members` WHERE `username` = '".$_POST['username']."'");
      $q3 = mysql_fetch_obj ect($q2);
      if($q3->username == $_POST['username']) {
      die('<BR><BR>So rry, but the username "'.$q3->username.'" is taken, please choose another.');
      /* here I got to suggest the user different available usernames taking his Firstname, Middled name and Last name as input..it looks something like this..but I am sure it is not efficient and there are lots of different available usernames that I have to consider by each time checking it against database..thats is not done below as I was buzy considering the different kind of usernames..and I feel miserable to have such a lengthy code...is tehre any other efficient form of coding*???*/

      <?php
      $un = $_POST["username"];
      $fn = $_POST["firstname"];
      //$fn = $_POST["middlename "];
      $ln = $_POST["lastname"];

      $un3= $fn.$ln;
      //echo $un3;
      for($i=0;$i<3;$ i++)
      {
      $r= $ln[0];
      $un4 = $fn.$ln.$r ;
      //check if it exist in database
      echo $un4;
      $un5 = $fn.$r ;
      //check database
      echo $un5;
      $un6 = $fn.$mn.$r ;
      //check database
      echo $un6;
      //use random number generator
      $s = rand(1,100);
      echo $s;
      /* here say the name is John Carlo Philip..then I got to make probability of arranging this name in n number of ways and each checking against database and when atleast 3 or 4 such available usernames are found then display it to user*/
      }
      ?>[/php]
      Please read the Posting Guidelines before you post in this forum!. If you want everyone to be able to read your code, then enclose it within the code, html or php tags!!

      moderator :cool:
      Last edited by ronverdonk; Jan 10 '07, 04:48 PM. Reason: enclosing code with tags

      Comment

      • subash
        New Member
        • Sep 2006
        • 32

        #4
        Hi Preetham,

        I think the following link might be helpful for you :


        An user based login - article

        Subash :)

        Comment

        • RPreetham
          New Member
          • Jan 2007
          • 6

          #5
          Thanks..but that link does not suggeest available ids..

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Since you already have the code to check for available ids, your problem is simply to find a new username. You want to use the username, first name and surname. Some suggestions are as follows:
            Use the username and initials (first letter of first name and surname)
            Use the username, initials, and a number (start with 1)
            Use the username and first name
            Use the username and surname
            Combine the above with 1, 2, 3, etc.
            Of course, in each case, search the database to make sure the suggested username is not already taken. If not, display it otherwise suggest another one.
            I'll trust you know the string functions that you can can use to derive certain letters and concatenate strings, etc. If not, see the manual for string functions here, in particular the substr function should be useful.

            Comment

            • RPreetham
              New Member
              • Jan 2007
              • 6

              #7
              Yes This is exactly what I did ..I wanted to know is there any other efficient manner...
              I used the string functions too..
              I am making all the combination of username ,first name ,last name and then combine the name with number etc..and each time checking the database...
              So I guess this is the only way to do that...
              Thnaks

              Comment

              • AricC
                Recognized Expert Top Contributor
                • Oct 2006
                • 1885

                #8
                Originally posted by subash
                Hi Preetham,

                I think the following link might be helpful for you :


                An user based login - article

                Subash :)
                If your looking for a login script I would do a search for PHP + Login on this site. A month or two ago Ronverdonk did an outstanding example of a PHP login script with SHA1 password encryption, I think it is much easier to read/follow than the one in the link.

                Comment

                • RPreetham
                  New Member
                  • Jan 2007
                  • 6

                  #9
                  Thank You so much..I will check it out

                  Comment

                  • RPreetham
                    New Member
                    • Jan 2007
                    • 6

                    #10
                    I checked that site..but it does not have the stuff to generate names...Anyway I may try it out myself.Thank You

                    Comment

                    Working...